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_attribute not written by the markdown writer #4311

Closed
tolot27 opened this issue Jan 26, 2018 · 5 comments
Closed

raw_attribute not written by the markdown writer #4311

tolot27 opened this issue Jan 26, 2018 · 5 comments

Comments

@tolot27
Copy link
Contributor

tolot27 commented Jan 26, 2018

with pandoc 2.1.1 and a file header_with.md with content:

---
header-includes:
- '`\usepackage{todonotes}`{=latex}'
...

# Test

Some text.

and pandoc -s -t native header_with.md prints:

Pandoc (Meta {unMeta = fromList [("header-includes",MetaList [MetaInlines [RawInline (Format "latex") "\\usepackage{todonotes}"]])]})
[Header 1 ("test",[],[]) [Str "Test"]
,Para [Str "Some",Space,Str "text."]]

but the raw attribute is removed if pandoc -s -t markdown header_with.md gets called:

---
header-includes:
- '\usepackage{todonotes}'
---

\usepackage{todonotes}

Test
====

Some text.

It does not matter if I explicitly enable the raw_attribute extension for the input or output format.

Not only the raw attribute {=latex} gets removed, also the complete line \usepackage{todonotes} gets duplicated and printed after the yaml header.

@jgm
Copy link
Owner

jgm commented Jan 28, 2018 via email

@tolot27
Copy link
Contributor Author

tolot27 commented Jan 31, 2018

I did not fully understand the rationale behind it. From the manual:

Raw content to include in the document’s header may be specified using header-includes; however, it is important to mark up this content as raw code for a particular output format, using the raw_attribute extension), or it will be interpreted as markdown. For example:

Hence, it becomes mandatory to mark up at least raw code in header-includes with the raw attribute. That is what I did.

Nevertheless, the header-includes should not be repeated outside of the yaml block. Even if it does not make much sense at all, pandoc -s -t markdown header_with.md -o - | pandoc -s -f markdown -t markdown repeatedly copies the header-includes statement outside of the yaml block.

@jgm
Copy link
Owner

jgm commented Feb 2, 2018

Even if it does not make much sense at all, pandoc -s -t markdown header_with.md -o - | pandoc -s -f markdown -t markdown repeatedly copies the header-includes statement outside of the yaml block.

This is because the default markdown template includes a variable to be filled with the contents of header-includes. I agree, this gives weird results when your header-includes are already specified in the YAML metadata, but when we're resolving the template, we don't know whether header-includes were specified with an external file.

You can always remove this variable from your markdown template.

@jgm
Copy link
Owner

jgm commented Feb 2, 2018

I think that using the explicit raw attribute for all raw content, if the extension is enabled, is the way to go.

@gpoore
Copy link

gpoore commented May 20, 2018

I just ran across a variation on this in pandoc 2.2. When round-tripping markdown (pandoc -f markdown -t markdown), it's currently possibly to use LaTeX macros to create markdown text (in which any LaTeX macros have been expanded).

Markdown example:

\newcommand{\code}[1]{`#1`{.lang}}

BEFORE \code{x} AFTER

BEFORE `` `x`{.lang}``{=latex} AFTER

Output of pandoc -f markdown -t markdown:

\newcommand{\code}[1]{`#1`{.lang}}
BEFORE `x`{.lang} AFTER

BEFORE `x`{.lang} AFTER

If this is then piped through pandoc -f markdown -t latex, we get

\newcommand{\code}[1]{`#1`{.lang}}

BEFORE \texttt{x} AFTER

BEFORE \texttt{x} AFTER

Meanwhile, sending the original markdown straight to LaTeX with pandoc -f markdown -t latex gives the very different output

\newcommand{\code}[1]{`#1`{.lang}}

BEFORE `x`{.lang} AFTER

BEFORE `x`{.lang} AFTER

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

3 participants