There are hacks for defining \newcommand
in a jupyter markdown cell (just include $\newcommand\whatever$
inside a markdown cell. This doesn't render the code but the new command is active throughout the notebook.) OR when using nbconvert (just include \newcommand\whatever
in a raw nbconvert cell. This adds it to the .tex before compiling).
However, the first solution doesn't work when you try to export to PDF and the second doesn't work within the notebook itself. If I include the new command both ways, it works in the notebook (since the raw cell is ignored) but it still doesn't export to PDF and the raw cell is visible in the notebook.
Is there a clean solution that gets me both a working notebook and PDF export?