Skip to content

Latex macros in Jupyter Lab #207

@xt0r3-Cambridge

Description

@xt0r3-Cambridge
          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 jupyterlab/jupyterlab#5997 (comment)

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions