Pandoc: Latex writer eats usepackage in header-includes

Created on 5 Aug 2019  ·  6Comments  ·  Source: jgm/pandoc

I'm trying to convert a markdown document to PDF using LaTeX, and need some special things setup on the LaTeX side of things. I can use header-includes to pass through some commands just fine, but I need to load a package and pandoc is parsing an eating all attempts to use \usepackage{}.

$ pandoc -s -t latex                                                                                                                         
---
header-includes:
  - \usepackage{ucharclasses}
  - \setlength\parident{0pt}
---
\LaTeX
^D

The output will have the length definition but the usepackage command will be stripped out.

I see in the changelog that in Pandoc 1.9:

LaTeX \include and \usepackage commands are now processed, provided the files are in the working directory.

This is probably a side affect of this, but it seems like it's being too greedy. I just need to pass the code on to LaTeX, I don't need pandoc to interpret whether it's valid or not.

LaTeX reader

Most helpful comment

@alerque if you use header-includes and the raw attribute syntax all the time everything should Just Work. There is however a detail which isn't mentioned in the manual and which apparently trips many people: the backtick is a reserved, though currently unused, character in YAML so you have to put everything which uses them in a YAML block scalar or (single) quoted string:

````````yaml
header-includes:

  • |
    {=latex} \usepackage{thispackage}
  • '\usepackage{thatpackage}{=latex}'
    ````````

The new YAML parser throws an error on unquoted backticks, but I suspect that people don't understand the error and/or don't know the fix and so wrongly conclude that raw attribute syntax doesn't work in metadata. I think I'll do a pull request adding a description of the problem with backticks in YAML to the manual.

All 6 comments

For this use-case, you can use https://pandoc.org/MANUAL.html#generic-raw-attribute

---
header-includes: |
  - |
  ```{=latex}
  \usepackage{ucharclasses}
  \setlength\parident{0pt}
  ```
---

We might want to explore making this a little smoother, by treating usepackage (and other includes) as raw latex blocks when the raw_tex extension is enabled, and otherwise doing what we're doing now.

That would be nice, yes. The experience is pretty rough right now. Just when you think you've got it figured out how to pass TeX code into the preamble, it doesn't work for one line of code when it worked for another. The process is quite confusing actually, even having read the docs.

Also there are a _lot_ of places online that have this technique documented. What they don't explain is that ⓐ this only worked before a certain version and ⓑ still works now but only for specific packages.

@alerque if you use header-includes and the raw attribute syntax all the time everything should Just Work. There is however a detail which isn't mentioned in the manual and which apparently trips many people: the backtick is a reserved, though currently unused, character in YAML so you have to put everything which uses them in a YAML block scalar or (single) quoted string:

````````yaml
header-includes:

  • |
    {=latex} \usepackage{thispackage}
  • '\usepackage{thatpackage}{=latex}'
    ````````

The new YAML parser throws an error on unquoted backticks, but I suspect that people don't understand the error and/or don't know the fix and so wrongly conclude that raw attribute syntax doesn't work in metadata. I think I'll do a pull request adding a description of the problem with backticks in YAML to the manual.

@bpj Thanks for the feedback. I think maybe your example has one too many backticks in the first (blockwise) usage, no?

@alerque No there aren't too many backticks. Three is the minimum, but no
maximum is mentioned anywhere that I'm aware of. When using Vim I often do
60I`<esc> to get a fence which goes across the window, as I think
that looks better.

Den ons 28 aug. 2019 11:20Caleb Maclennan notifications@github.com skrev:

@bpj https://github.com/bpj Thanks for the feedback. I think maybe your
example has one too many backticks in the first (blockwise) usage, no?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/jgm/pandoc/issues/5673?email_source=notifications&email_token=AAI3OUZNZS53KUBZZWHDXBLQGY7KZA5CNFSM4IJHVXF2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5KOWNQ#issuecomment-525658934,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAI3OU74Y6GYDXQDPD2YFOLQGY7KZANCNFSM4IJHVXFQ
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jgm picture jgm  ·  48Comments

phyllisstein picture phyllisstein  ·  84Comments

graymalkin picture graymalkin  ·  54Comments

elliottslaughter picture elliottslaughter  ·  44Comments

ERnsTL picture ERnsTL  ·  58Comments