Skip to content

New extension: load_tex_macros.#1257

Merged
jfbercher merged 3 commits intoipython-contrib:masterfrom
ketch:load_tex_macros
Mar 7, 2018
Merged

New extension: load_tex_macros.#1257
jfbercher merged 3 commits intoipython-contrib:masterfrom
ketch:load_tex_macros

Conversation

@ketch
Copy link
Copy Markdown
Contributor

@ketch ketch commented Mar 5, 2018

Just loads a tex file whenever a notebook is loaded, then re-runs mathjax. Useful if you have several notebooks that use a common set of latex macros, so you don't have to copy the macros to each notebook.

Essentially all credit for this goes to @jfbercher who practically wrote the extension for me; it's based on one of the functions from his latex_env extension.

@ketch
Copy link
Copy Markdown
Contributor Author

ketch commented Mar 6, 2018

It looks like all the Travis jobs that actually ran passed. There are some failures, but those jobs seem never even to have started.

What can I do to help git this PR merged?

Copy link
Copy Markdown
Member

@jcb91 jcb91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me, a couple of comments inline, but in general I see nothing here that won't work, and certainly nothing that will break anything else

@@ -0,0 +1,7 @@
Type: IPython Notebook Extension
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change this to Jupyter Notebook Extension? Thanks!

@jcb91
Copy link
Copy Markdown
Member

jcb91 commented Mar 6, 2018

Travis builds restarted, but they aren't going to check anything relevant for this all-js extension anyway, tbh, so not a problem to ignore them here if they fail...

@ketch
Copy link
Copy Markdown
Contributor Author

ketch commented Mar 6, 2018

@jcb91 Thanks for the review. I changed "IPython" to "Jupyter".

if ($('#latexdefs').length > 0) $('#latexdefs').remove();
$('body').append($('<div/>').attr('id', 'latexdefs').text(data));
console.log('latex_envs: loaded user LaTeX definitions latexdefs.tex');
onMarkdownCellRendering();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure it works because function onMarkdownCellRendering() is not defined. It is defined in latex_envs and is global (which is not a good practice indeed), but in the absence of latex_envs extension, this will not work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, somehow it works for me even with latex_envs disabled.

Link: readme.md
Icon: icon.png
Main: main.js
Compatibility: 4.x
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add 5.X in Compatibility: 4.x, 5.x

function rerenderMaths() { // probably something like that
MathJax.Hub.Queue(
["PreProcess", MathJax.Hub], ["Reprocess", MathJax.Hub]
);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think

MathJax.Hub.Queue(
  ["resetEquationNumbers",MathJax.InputJax.TeX],
  ["PreProcess",MathJax.Hub],
  ["Reprocess",MathJax.Hub]
);

could be better (resets equation numbers before reprocessing avoid an issue with labels in equations that cannot be rendered several times without reset.

Usage
=====

Simply put your latex macros in a file named latexdefs.tex, in the same directory as your notebook.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps "This is mainly derived from jupyter_latex_envs, following the discussion here".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry! didn't read the mention at the beginning. Thanks.

Compatible with 5.x.
Correctly reprocess mathjax, including resetting equation numbers.
Better readme.
@ketch
Copy link
Copy Markdown
Contributor Author

ketch commented Mar 7, 2018

Okay, I've incorporated all the suggestions form @jfbercher . I think this is ready to go now.

@jfbercher
Copy link
Copy Markdown
Member

Nice and useful. Thanks @ketch!

@jfbercher jfbercher merged commit f40eb5b into ipython-contrib:master Mar 7, 2018
@ketch ketch deleted the load_tex_macros branch July 1, 2018 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants