Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nthiery opened this issue Sep 21, 2023 · 4 comments
Closed

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

nthiery opened this issue Sep 21, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@nthiery
Copy link
Contributor

nthiery commented Sep 21, 2023

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 :-)

@nthiery nthiery added the enhancement New feature or request label Sep 21, 2023
@rowanc1
Copy link
Collaborator

rowanc1 commented Nov 3, 2023

Related to #714.

@nthiery
Copy link
Contributor Author

nthiery commented Nov 5, 2023

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:

  • It should really be implemented on the transformers side to behave differently for latex and other exports. For now, I am using a dedicated myst.yml for my latex export which loads this extension.
  • The latex exporter quotes latex commands embedded in text nodes. I hacked around this by building math nodes and escaping out of math mode with additional $.

@rowanc1
Copy link
Collaborator

rowanc1 commented Aug 22, 2024

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

@rowanc1 rowanc1 closed this as completed Aug 22, 2024
@nthiery
Copy link
Contributor Author

nthiery commented Aug 22, 2024

Yeah! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants