jfbercher / jupyter_latex_envs

(Some) LaTeX environments for Jupyter
Other
112 stars 28 forks source link

Conversion to slide not taking extensions into account #36

Open hugues-talbot opened 6 years ago

hugues-talbot commented 6 years ago

Hello,

I cannot make use of both reveal.js slides and latex notebook extensions. In the slides, I simply get the unconverted code (see screenshot).

In other words, a command like

jupyter nbconvert --to slides_with_lenvs

is mssing.

screenshot 2018-02-20 16 52 22
jfbercher commented 6 years ago

This is a good idea for improvement and should be easy. For now, you can try to

AhAh. No. Not that easy. :-( There is a dedicated exporter for slides, which adds data to the notebook itself before conversion; so one has to keep all that in a special preprocessor. I write this in my todo...


If you are really in a hurry, you can (probably) convert to slides, and then add latex_envs support by hands. Add this at the beginning

<!-- javascript from CDN for conversion -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.js"></script>

<script type="text/x-mathjax-config">
// make sure that equations numbers are enabled
MathJax.Hub.Config({ TeX: { equationNumbers: {
    autoNumber: "AMS", // All AMS equations are numbered
    useLabelIds: true, // labels as ids
    // format the equation number - uses an offset eqNumInitial (default 0)
    formatNumber: function (n) {return String(Number(n)+Number(1)-1)} 
    } } 
});
</script>

and this at the end of the head (before </head>)

<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">

<!-- stylesheet from CDN -->
<link rel="stylesheet" type="text/css" href="https://rawgit.com/jfbercher/jupyter_latex_envs/master/src/latex_envs/static/latex_envs.css">

<!-- Custom stylesheet, it must be in the same directory as the html file -->
<link rel="stylesheet" href="custom.css"> 

<!-- Load mathjax 
<script src="https://rawgit.com/ipython-contrib/jupyter_contrib_nbextensions/master/src/jupyter_contrib_nbextensions/nbextensions/latex_envs/thmsInNb4.js"></script>
-->
<script type="text/javascript"  src="https://rawgit.com/jfbercher/jupyter_latex_envs/master/src/latex_envs/static/thmsInNb4.js"> </script>

<script>
$( document ).ready(function(){

        //Value of configuration variables, some taken from the notebook's metada. 
        eqNum = 0; // begins equation numbering at eqNum+1
        eqLabelWithNumbers = "True"=="True" ? true : false; //if true, label equations with equation numbers; 
                                       //otherwise using the tag specified by \label
        conversion_to_html = false;
        current_cit=1;
        cite_by='key';  //only number and key are supported
        //var document={}
        document.bibliography={};

        // Read environment map config
        initmap();
        // Read user envs config, if specified        
                environmentMap = $.extend(true,{}, environmentInitialMap)                

        // fire the main function with these parameters
        var html_to_analyse = $('body').html()
        var html_converted = thmsInNbConv(marked,html_to_analyse);
        html_converted = html_converted.replace(/%[\S\t ]*<\/p>/gm,"</p>")
        $('body').html(html_converted)
        // Show/hide anchors
        var labels_anchors = "False"=="True" ? true : false;
        $('.latex_label_anchor').toggle(labels_anchors)
        // Number all environments
        report_style_numbering = "False"=="True" ? true : false;
        reset_counters();
        renumberAllEnvs();
    });
</script
jfbercher commented 6 years ago

Export to slides using

jupyter nbconvert --to slides_with_lenvs FILE.ipynb

is available in version 1.4.3 at Pypi of in this repo. Enjoy.

hugues-talbot commented 6 years ago

Hello JFB

As stated, this works well. This yields a single HTML page with the correct equations, numberings, etc. Very useful !

However it does not work with reveal.js

jupyter nbconvert --to slides_with_lenvs Perceptron.ipynb --post serve

Yields (see screenshot).

[Math Processing Error] \newcommand{\M}[1]{\mathbf{#1}}

Any idea ?

Thanks again.

On Feb 24, 2018, at 9:44 PM, Jean-François Bercher notifications@github.com wrote:

Export to slides using

jupyter nbconvert --to slides_with_lenvs FILE.ipynb is available in version 1.4.3 at Pypi https://pypi.python.org/pypi/jupyter_latex_envs/1.4.3 of in this repo. Enjoy.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jfbercher/jupyter_latex_envs/issues/36#issuecomment-368258859, or mute the thread https://github.com/notifications/unsubscribe-auth/ABfDUBJ5pIv0H_S7pr2ZDfm28KtOSp2Rks5tYHTLgaJpZM4SMLr8.

jfbercher commented 6 years ago

There is no screenshot.

Anyway this is probably unrelated to latex_envs. It means that your mathjax processor fails somewhere; because of your browser, your internet connexion or of cache issues. Try to clear the cache (press shift while reloading; or use your browser preferences).

hugues-talbot commented 6 years ago

OK it might indeed be a browser issue indeed because with the fixed HTML version (without the reveal.js script) I sometime get the error, sometime not.

On Feb 27, 2018, at 11:49 AM, Jean-François Bercher notifications@github.com wrote:

There is no screenshot.

Anyway this is probably unrelated to latex_envs. It means that your mathjax processor fails somewhere; because of your browser, your internet connexion or of cache issues. Try to clear the cache (press shift while reloading; or use your browser preferences).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jfbercher/jupyter_latex_envs/issues/36#issuecomment-368829085, or mute the thread https://github.com/notifications/unsubscribe-auth/ABfDUCTR0WmbpfSsAoRDR4D9j7LudLVmks5tY92mgaJpZM4SMLr8.

hugues-talbot commented 6 years ago

It works well in Firefox & Chrome after restarting the browsers. Thanks !

On Feb 27, 2018, at 12:01 PM, Hugues Talbot <hugues.talbot@gmail.com mailto:hugues.talbot@gmail.com> wrote:

OK it might indeed be a browser issue indeed because with the fixed HTML version (without the reveal.js script) I sometime get the error, sometime not.

On Feb 27, 2018, at 11:49 AM, Jean-François Bercher <notifications@github.com mailto:notifications@github.com> wrote:

There is no screenshot.

Anyway this is probably unrelated to latex_envs. It means that your mathjax processor fails somewhere; because of your browser, your internet connexion or of cache issues. Try to clear the cache (press shift while reloading; or use your browser preferences).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jfbercher/jupyter_latex_envs/issues/36#issuecomment-368829085, or mute the thread https://github.com/notifications/unsubscribe-auth/ABfDUCTR0WmbpfSsAoRDR4D9j7LudLVmks5tY92mgaJpZM4SMLr8.

jfbercher commented 6 years ago

:smiley: