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

Latex writer eats usepackage in header-includes #5673

Closed
alerque opened this issue Aug 5, 2019 · 6 comments
Closed

Latex writer eats usepackage in header-includes #5673

alerque opened this issue Aug 5, 2019 · 6 comments

Comments

@alerque
Copy link
Contributor

alerque commented Aug 5, 2019

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.

@mb21
Copy link
Collaborator

mb21 commented Aug 5, 2019

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

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

@jgm
Copy link
Owner

jgm commented Aug 5, 2019

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.

@alerque
Copy link
Contributor Author

alerque commented Aug 5, 2019

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.

@jgm jgm added this to the 2.7.4 milestone Aug 6, 2019
@bpj
Copy link

bpj commented Aug 6, 2019

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

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.

@alerque
Copy link
Contributor Author

alerque commented Aug 28, 2019

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

@bpj
Copy link

bpj commented Aug 31, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants