jupyter-book / mystmd

Command line tools for working with MyST Markdown.
https://mystmd.org/guide
MIT License
214 stars 64 forks source link

Provide a role to inject code in the latex output #613

Closed nthiery closed 2 months ago

nthiery commented 1 year ago

One of the (few) remaining reasons to produce LaTeX/PDF exports is when fine-tuning of the layout is required for printing.

Proposal

Provide a latexonly role that inserts its content verbatim in the produced LaTeX exports, and is ignored by all other exporters.

Example:

 {latexonly}`\pagebreak`
 {latexonly}`\bigskip`
 {latexonly}`\enlargethispage{1cm}`

A use case

I print my exercise sheets for 250 students. I typically end up tuning the layout by inserting vertical skips, page breaks, page enlargements, so that exercises don't get split across pages for readability, while optimizing page numbers (a one page gain saves one package of paper!). As I am switching my sheets from latex to MyST, I would like to keep that ability.

Fun fact

I am currently desperate enough to hijack in my latex template <s></s> to insert page breaks and <i></i> to insert vertical spacing :-)

rowanc1 commented 1 year ago

Related to #714.

nthiery commented 1 year ago

For information, in case this can be useful to others (@alanlujan91?): I cooked myself a quick and (very) dirty latexonly extension for my urgent needs:

https://gitlab.dsi.universite-paris-saclay.fr/Info111/Info111/-/blob/master/extensions/latexonly.mjs?ref_type=heads

Beware:

rowanc1 commented 2 months ago

This now working with the {raw:tex} directive and role, which can be used to insert raw latex code that is not parsed.

An example: https://github.com/executablebooks/mystmd/blob/main/packages/mystmd/tests/raw/index.md#L6

nthiery commented 2 months ago

Yeah! Thank you!