jupyterlab / jupyterlab-latex

JupyterLab extension for live editing of LaTeX documents
BSD 3-Clause "New" or "Revised" License
608 stars 70 forks source link

Latex macros in Jupyter Lab #207

Open xt0r3-Cambridge opened 1 year ago

xt0r3-Cambridge commented 1 year ago
          So this would work?
<div hidden>
\newcommand{\require}[1]{}

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

\vskip-\parskip
\vskip-\baselineskip

</div>

Originally posted by @jasongrout in https://github.com/jupyterlab/jupyterlab/issues/5997#issuecomment-475289432

The above approach did not work for me when trying to export as PDF.

I have since tried many other approaches, and the one that happened to work by some miracle is this:

<div hidden>
\[
\iffalse \textrm{General purpose macros} \fi
\renewcommand{\deg}{{^{\circ}}}
\newcommand{\rbr}[1]{{\left({{#1}}\right)}}
\newcommand{\abr}[1]{{\left\langle{{#1}}\right\rangle}}
\newcommand{\cbr}[1]{{\left\{{{#1}}\right\}}}
\newcommand{\sbr}[1]{{\left[{{#1}}\right]}}
\newcommand{\pipe}[1]{{\left|{{#1}}\right|}}
\newcommand{\ppipe}[1]{{\left\|{{#1}}\right\|}}
\newcommand{\floor}[1]{{\left\lfloor{{#1}}\right\rfloor}}
\newcommand{\ceil}[1]{{\left\lceil{{#1}}\right\rceil}}
\newcommand{\set}[1]{{ \cbr{{#1}} }}
\iffalse \textrm{Semantics macros} \fi
\newcommand{\iet}[3]{{\textrm{if } {{#1}} \textrm{ then } {{#2}} \textrm{ else } {{#3}}}}
\renewcommand{\t}[1]{{\textrm{true}}}
\newcommand{\f}[1]{{\textrm{false}}}
\iffalse \textrm{Compiler Construction macros} \fi
\newcommand{\fst}[1]{{\textrm{FIRST}({{#1}})}}
\newcommand{\flw}[1]{{\textrm{FOLLOW}({{#1}})}}
\newcommand{\gen}[2][]{{ {{#1}} \implies {{#2}} }} 
\]
</div>

I have no idea why this works and the other approaches don't, but in case anyone is looking for a quick and dirty fix, there you go. Also, note that there can be no line breaks between the lines or this won't work.

You will need to shut down the notebook and restart it after adding the macros and it should work.

welcome[bot] commented 1 year ago

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively. welcome You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada: