How to define a macro in a Jupyter cell?

I quickly tried the JL trick and it works nicely in both the JL display and the LaTex export. I extended the trick sample a bit.

<div hidden>
\newcommand{\require}[1]{}

$\require{begingroup}\require{newcommand}$
$\gdef\vec#1{\boldsymbol{#1}}$

\vskip-\parskip
\vskip-\baselineskip

</div>

<div hidden>

$\gdef\part#1#2{\dfrac{\partial #1}{\partial #2}}$

\vskip-\parskip
\vskip-\baselineskip

</div>

Apparently you only issue the \newcommand and \require statements once, Otherwise you get a LaTeX compile error.

So we have tricks that work in Jupyter notebook and Jupyter lab. They are unfortunately not the same tricks, so you cannot edit the same ipynb in both tools and get the same results. This sounds like a work-around (which is good) but not a full solution.

Is there a good place to document this so other folks will not have to dig it out in bits and pieces?

1 Like