Need help with custom.js

181 views
Skip to first unread message

Андрей Ширшов

unread,
May 5, 2017, 3:06:17 PM5/5/17
to Project Jupyter
Hello!

In Jupyter Notebook ver. 4 I had custom.js file I attached.
After updating to Jupyter Notebook ver. 5 anything in this file stopped to work.
I cann't understand why. I have only poor knowledge of js, so it's difficult
for me to fix it. I collected all settings from internet and it's not comfortable
to work now without these settings.

Please tell me what and how can I fix to make my code work.

For your comfort the content of custom.js file is below:

console.log("load clipboard.js");
requirejs.config({
    paths: { 
        'clipboard': ['notebook/js/clipboard.min']
    },
    shim: {
        clipboard: {
            deps: [],
            export: "clipboard"
        }
    }
});

// How to use:
// %%html
// <button class="btn" data-clipboard-text="Just because you can doesn't mean you should — clipboard.js">
//     Copy to clipboard
// </button>
// <script>
// require(['clipboard'], function(Clipboard){
//         var clipboard = new Clipboard('.btn')
//     });
// </script>

define([
    'base/js/namespace',
    'codemirror/keymap/sublime', // This is js file too!
    'base/js/events'
    ], 
    function(IPython, sublime_keymap, events) {
        events.on("app_initialized.NotebookApp", 
            function () {
                console.log("Load settings for codemirror cells")
                var cell = require("notebook/js/cell").Cell;
                cell.options_default.cm_config.lineNumbers = true;
                cell.options_default.cm_config.keyMap = 'sublime';
                cell.options_default.cm_config.lineWrapping = true;
                cell.options_default.cm_config.autoCloseBrackets = true;
            }
        );
    }
);

// This settings must be applied before mathjax will be loaded
// because mathjax will apply all setting immediatelly after its loading.
// We shouldn't use define function for this because mathjax
// is loaded from <script> in html code (without using require.js).
console.log("Load Mathjax settings")
// Mathjax settings for Russian math.
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ["$","$"], ["\\(","\\)"] ],
        displayMath: [ ["$$","$$"], ["\\[","\\]"] ],
        processEscapes: true,
    },
    TeX: {
        Macros: {
            Alpha: "\\mbox{A}",
            Beta: "\\mbox{B}",
            Epsilon: "\\mbox{E}",
            Zeta: "\\mbox{Z}",
            Eta: "\\mbox{H}",
            Iota: "\\mbox{I}",
            Kappa: "\\mbox{K}",
            Mu: "\\mbox{M}",
            Nu: "\\mbox{N}",
            Omicron: "\\mbox{O}",
            Rho: "\\mbox{P}",
            Tau: "\\mbox{T}",
            Chi: "\\mbox{X}",
            and: "\\mbox{&}",
            or: "\\lor",
            exist: "\\exists",
            empty: "\\emptyset",
            P: "\\mbox{P}",
            tan: "\\operatorname{tg}",   // tangent
            tg: "\\operatorname{tg}",    // tangent
            cot: "\\operatorname{ctg}",  // cotangent
            ctg: "\\operatorname{ctg}",  // cotangent
            csc: "\\operatorname{cosec}",     // cosecant
            cosec: "\\operatorname{cosec}",   // cosecant
            arctan: "\\operatorname{arctg}",  // arctangent
            arctg: "\\operatorname{arctg}",   // arctangent
            arccot: "\\operatorname{arcctg}",      // arc cotangent
            arcctg: "\\operatorname{arcctg}",      // arc cotangent
            arcsec: "\\operatorname{arcsec}",      // arc secant
            arccsc: "\\operatorname{arccosec}",    // arc cosecant
            arccosec: "\\operatorname{arccosec}",  // arc cosecant
            sh: "\\operatorname{sh}",     // hyperbolic sine
            ch: "\\operatorname{ch}",     // hyperbolic cosine
            th: "\\operatorname{th}",     // hyperbolic tangent
            cth: "\\operatorname{cth}",   // hyperbolic cotangent
            sinh: "\\operatorname{sh}",   // hyperbolic синус
            cosh: "\\operatorname{ch}",   // hyperbolic cosine
            tanh: "\\operatorname{th}",   // hyperbolic tangent
            coth: "\\operatorname{cth}",  // hyperbolic cotangent
            sgn: "\\operatorname{sgn}",
            mod: "\\operatorname{mod}",
            ge: "\\geqslant",
            le: "\\leqslant",
            geq: "\\geqslant",
            leq: "\\leqslant",
            N: "\\mathbb{N}",
            R: "\\mathbb{R}",
            Q: "\\mathbb{Q}",
            Z: "\\mathbb{Z}",
            C: "\\mathbb{C}",
            H: "\\mathbb{H}",
            P: "\\mathbb{P}",
            dmtr: "\\unicode{x2300}", // diameter sign
            deg: "\\unicode{xb0}",    // degree sign
            celdeg: "\\unicode{x2103}"   // degree Celsius sign
        },
        // AutoNumbering of displayed formulas
        equationNumbers: { autoNumber: "AMS" },
        // All mathjax extensions:
        // Source code for all extensions:
        extensions: [
        "color.js", // Color support in LaTeX
        "autobold.js", // support for \boldsymbol{...}
        "AMSmath.js",
        "AMSsymbols.js",
        "AMScd.js", // http://www.jmilne.org/not/Mamscd.pdf
        "bbox.js", // support for \bbox[options]{math}
        // "begingroup.js", // mainly for formulas localization
        "cancel.js" // support for strikethrough formulas
        // "HTML.js" // works by default
        // "mhchem.js" // chemical formulas
        // "uniconde.js" // works by default
        ]
    }
});

Best regards, Andrey.

custom.js

Adam Rule

unread,
May 8, 2017, 12:13:42 PM5/8/17
to Project Jupyter
Hi Andrey,

Are you seeing any errors in your browser console when you have a notebook open? That could help us diagnose the problem.

If you are using Google Chrome, you can find the console in your Developer Tools, which you can access by right clicking and selecting "Inspect" or the View > Developer > Developer Tools (at least that's how I reach it on Mac).

-adam

Андрей Ширшов

unread,
May 8, 2017, 1:18:11 PM5/8/17
to Project Jupyter
Hi, Adam!

I see messages from custom.js in browser console (I attached screenshot), but all still not working:

* there is no line numbers in code cells,
* there is no sublime mode in code cells,
* copy in clipboard using clipboardjs doesn't work
* my mathjax settings doesn't work too.

It seems to me that API changed. And some trigger stopped to work (for example https://github.com/jupyter/notebook/issues/2403).
And it seems to me it's the main cause my old script stoped to work.

Best regards, Andrey.




понедельник, 8 мая 2017 г., 19:13:42 UTC+3 пользователь Adam Rule написал:
chrome developer tool.png

Adam Rule

unread,
May 22, 2017, 2:43:26 PM5/22/17
to Project Jupyter
Hmm, not much useful information in that console. What about on the Python side? How do you launch your notebooks? If from a Terminal, do you see any error messages int he terminal output?
Reply all
Reply to author
Forward
0 new messages