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

Raw header-includes #7926

Closed
phmarek opened this issue Feb 17, 2022 · 8 comments
Closed

Raw header-includes #7926

phmarek opened this issue Feb 17, 2022 · 8 comments
Labels

Comments

@phmarek
Copy link

phmarek commented Feb 17, 2022

I'm running pandoc 2.17.1.1-1 amd64 on Debian.

I've got a few HTML files that I convert to tex via my own template; also, I'd like to expand a few variables in the template via a metadata.yaml file:

---
title: my title
author:
- XYZ
- ABC
header-includes:
- |
  ```{=latex}
  \setlength\LTleft\parindent
  \setlength\LTright\fill
  \AddToHook{cmd/section/before}{\clearpage}
  ```
---

According to MANUAL.txt, #3300, #2139, and/or 2b34337 this is the exact syntax I should be using; still, it doesn't work.

The authors and the title are correctly replaced in the template -- but then I get

\texttt{\{=latex\}\ \textbackslash{}setlength\textbackslash{}LTleft\textbackslash{}parindent\ \textbackslash{}setlength\textbackslash{}LTright\textbackslash{}fill\ \textbackslash{}AddToHook\{cmd/section/before\}\{\textbackslash{}clearpage\}}

instead of the raw data.

The command line (broken for readability) is

pandoc --metadata-file=metadata.yaml -f html <html files> --default-image-extension=svg  --variable <some>
   --extract-media <dir1> --extract-media <dir2> --number-sections --toc --pdf-engine=xelatex  --template=<template file>
   --standalone -t latex -o <output>

I also tried html+raw_attribute, but despite raw_attribute being listed as generic it's not accepted with html.

Is that a recent regression, or am I just not understanding how to use pandoc?

Thank you so much for your help!!

[update: removed "# vim: set et :" comment from yaml, that confused github issue rendering]

@phmarek phmarek added the bug label Feb 17, 2022
@phmarek phmarek changed the title Raw header-incluses Raw header-includes Feb 17, 2022
@tarleb
Copy link
Collaborator

tarleb commented Feb 17, 2022 via email

@phmarek
Copy link
Author

phmarek commented Feb 17, 2022 via email

@jgm
Copy link
Owner

jgm commented Feb 17, 2022

I fixed the code block in your original post. (Use four backticks for the surrounding code block if it contains a code block with three backticks.)

@jgm
Copy link
Owner

jgm commented Feb 17, 2022

OK, I believe this is an issue that has come up before. (I will look it up in the tracker soon.) The issue is this: in parsing the metadata file, we use the extensions enabled in the reader. Since your reader is html, which doesn't enable the fenced_code_block or raw_attribute extensions (these being markdown extensions), the content is parsed as "plain markdown."

@jgm
Copy link
Owner

jgm commented Feb 17, 2022

See #6832, #5914.

@jgm
Copy link
Owner

jgm commented Feb 17, 2022

Maybe we could do something like this:

  • if the reader format is markdown, parse the metadata file with the extensions enabled in the reader
  • if it is something else (e.g. html), parse the metadata file with markdown + standard default pandoc extensions

@phmarek
Copy link
Author

phmarek commented Feb 18, 2022

I just tried to use an HTML file like this:

<html><head>
<meta name=author-meta content=abc>
<meta name=title content=abc>
<meta name=header-includes content="\setlength...">
...

and had partial success -- the backslashes came up as \testbackslash again.

Sadly, content="```{=latex}...```" didn't work...

I found a workaround; by using another file and the command line option --include-in-header=header.tex I can get the contents in without any reformatting.

Thanks for the quick replies!

@jgm jgm closed this as completed in 5b84c0f Feb 18, 2022
@jgm
Copy link
Owner

jgm commented Feb 18, 2022

Fixed this by having pandoc use default pandoc markdown to parse metadata when the metadata format is not a markdown variant.

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

No branches or pull requests

3 participants