3 ms·
There's really no reason you need to switch. You can put raw LaTeX directly into Pandoc Markdown documents; it'll be ignored in non-LaTeX backends, and in LaTeX
by eslaught 5y ago
There's really no reason you need to switch. You can put raw LaTeX directly into Pandoc Markdown documents; it'll be ignored in non-LaTeX backends, and in LaTeX it'll just be reproduced verbatim. If you need to tweak the template that Pandoc puts "around" the Markdown content, you can do that too (and then centralize your changes so you don't need to do it over and over again). Eisvogel is an example of a project that does this [1].
I think this is really the best of both worlds, because you can produce documents that (fairly) easily generate print books via LaTeX while simultaneously generating webpages or ePubs for electronic distribution.
[1]: https://github.com/Wandmalfarbe/pandoc-latex-template https://github.com/Wandmalfarbe/pandoc-latex-template
- dredmorbius 5y agoWhilst true, you do lose the capability of using a single document source to generate multiple output formats (or at least do so easily) once you do that. A Markdown + LaTeX file processed with Pandoc will generate LaTeX or PDF outputs fine. It will stumble (or more likely: create incompletely formatted outputs) when you try generating other output formats. I am often using single source to create a number of output formats simultaneously (typically: PDF, HTML, ePub, possibly also plain text and PS). So long as I stick to a single markup language, Pandoc has a much easier time of it. Yes, you can embed multiple native formatting bits with some clever playing around with comment characters (I did manage to get both HTML and LaTeX going in one document I was working on, with Markdown as the nominal primary). That's ... not very elegant and tends to be fragile and error-prone. (I've a StackExchange post somewhere detailing how to do this for those interested.) My experience is that LaTeX is sufficiently simple and powerful that it's arguably the best underlying universal source. Using Pandoc, you can still produce HTML or ePub from LaTeX source. You might want to include or exclude some different front- and back-matter elements or other enclosures. For that I'd recommend developing a good standardised template model and build system (e.g., Makefiles).
- leephillips 5y agoYou don’t need to play tricks with comment characters. From the Pandoc manual (https://pandoc.org/MANUAL.html https://pandoc.org/MANUAL.html) [HN is messing with the backtics, but you get the idea]: Extension: raw_attribute Inline spans and fenced code blocks with a special kind of attribute will be parsed as raw content with the designated format. For example, the following produces a raw roff ms block: `````````{=ms} .MYMACRO blah blah ````````` And the following produces a raw html inline element: This is `<a>html</a>`{=html}
- dredmorbius 5y agoI'm trying to find my earlier example. This Reddit post describes the challenge / goal: https://old.reddit.com/r/pandoc/comments/7lnc38/is_it_possible_to_have_parallel_markdown_html_and/ https://old.reddit.com/r/pandoc/comments/7lnc38/is_it_possib... And ... found it. As you suggest, it turns out to be the raw_attribute extension which enables this. Note that this requires maintaining parallel content for each output format. https://stackoverflow.com/questions/48205029/pandoc-have-either-latex-or-markdown-html-render-but-not-both https://stackoverflow.com/questions/48205029/pandoc-have-eit... https://stackoverflow.com/questions/48083724/pandoc-markdown-ignore-text-in-pdf-but-include-in-html-updated https://stackoverflow.com/questions/48083724/pandoc-markdown...
- eslaught 5y agoYes, it requires parallel content. But I still think this is a better situation than a LaTeX source. While Pandoc can read LaTeX, it's limited to a fairly narrow subset. Anything you do outside of that will generate the raw formatting blocks the gp showed (and won't in general appear in any other format output). And you won't be left with any way to represent what should go in those places in HTML, ePub, etc. To put it in a more programmer centric way, Pandoc allows you to have the moral equivalent of ifdefs instead of maintaining separate source files for each output format. That's a huge advantage when you want to keep the content in sync.
- leephillips 5y ago