Pandoc markdown bold and color - latex

I am using pandoc and write my text in markdown. To create my own style I use a custom latex template.
I want to style all bold words with a color. So when I type **a word** this word should not only be bold, but also e.g. blue.
Using the following in my latex template file
\newcommand\boldblue[1]{\textcolor{blue}{\textbf{#1}}}
\renewcommand{\textbf}{\boldblue}
gives me an error when converting to pdf using
pandoc myfile -f markdown -t latex --template==mytemplate -o myfile.pdf
which says
TeX capacity exceeded, sorry (grouping levels = 255)
However: when I only set the newcommand
\newcommand\boldblue[1]{\textcolor{blue}{\textbf{#1}}}
I can write $\boldblue{some text}$ within my markdown file and it works.
Question: how do I set a new command for **<word>**?
Thanks!

After some more research I found the following solution using \let which works:
\let\oldtextbf\textbf
\renewcommand\textbf[1]{{\color{blue}\oldtextbf{#1}}}
Using this code in a template file converts markdown's **<some text>** to bold and blue in latex / pdf.

Related

How to remove number from toc title with pandoc+beamer

I am using pandoc to generate a beamer slideshow. I activated the generation of a TOC and specified a TOC headline. But there is an extra number added to this title as if the TOC would span several slides, but it does not.
My source file
---
toc: true
toc-title: the overview
...
# my section
and I compile with pandoc -t beamer -o x.pdf < x.md. The title of the TOC has this extra roman I which beamer normally adds if a slide is split into two (or more).
How can I get rid of this number?
Edit
In the end I put it in the yaml preamble of the pandoc file as raw latex code:
header-includes: |
```{=latex}
\setbeamertemplate{frametitle continuation}[from second]
% more stuff
```
You can disable the continuation count for frames that consist only of a single one by using this command:
\setbeamertemplate{frametitle continuation}[from second]
In the response from #samcarter_is_at_topanswers.xyz, I had to delimit the command with backticks and indicate as latex code:
`\setbeamertemplate{frametitle continuation}[from second]`{=latex}

citations in Pandoc footnotes rendered as numerals

I am getting a weird result when I convert markdown to PDF using Pandoc. This is for academic writing with footnotes generated via citeproc; a bibtex library generated by Zotero; and a Chicago csl file. Most of the footnotes are fine, but sometimes where I should see a book or article I just get a numeral.
When I write the following in Markdown
^[#melvilleMobyDick, 155]
I want a footnote that says
Herman Melville, Moby-Dick, p. 155
but I get
1, p. 155
The problem seems to be in the transition from markdown to LaTeX; the latter output is:
\footnote{1, 155}
My shell command is:
$ pandoc article.md -o article.latex --filter=pandoc-citeproc
And I am using this YAML header:
title: Essay
bibliography: My_Library.bib
csl: chicago_fullnote_ibid.csl
Many thanks for your help.
You're using chicago_fullnote_ibid.csl, which styles citations as footnotes. So just do [#melvilleMobyDick, 155] instead of ^[#melvilleMobyDick, 155] and it will turn into a footnote.

Pandoc generation of pdf from markdown 4th header is rendered differently

I am using pandoc to generate a pdf from some markdown. I am using h1 through h4 via hash symbols. Example h1=#, h4=####. When I generate my document like this:
pandoc input.md -o output.pdf
I get a document where h1, h2 and h3 have a newline after them but h4 does not have a new line. The text starts on the same line as the header (it isn't formatted the same way, but there isn't a newline character between).
I've tried adding spaces after the #### and adding manual line returns using my editor but nothing seems to work.
Any ideas?
While the mentioned solutions work fine, pandoc offers a build-in variable to enable block-headings for \paragraph.
pandoc -s -o out.pdf some.md -V block-headings
Pandoc Manual
pandoc generates PDFs via LaTeX. In LaTeX, "headers" are generated using the following commands:
\section
\subsection
\subsubsection
\paragraph
\subparagraph
As you can see, a "level four heading" corresponds to the \paragraph command, which is rendered as you describe. There simply isn't a \subsubsubsection command to use.
The only way to get what you want is to redefine the \paragraph command, which is quite tricky. I haven't been able to make it work with Pandoc.
While #tarleb’s answer is surely the best (except that it specifies a
wrong amount of vertical space), here is a “simpler” (by some measure)
but more hacky (in LaTeX terms at least) solution which optionally uses a Pandoc Lua filter or a LaTeX hack but avoids loading another LaTeX package.
We want the LaTeX source to look something like this:
\hypertarget{level-4-heading}{%
\paragraph{Level 4 heading}\label{level-4-heading}}
\hfill
Lorem ipsum dolor sit amet.
This LaTeX looks awful, but if you don’t need to keep or share the LaTeX
source it does what you probably want: a space between the level 4
heading and the paragraph after it equal to the space between a level 3
heading and the paragraph after it.
Here is how it works: since a \hfill on a line on its own is about as
close as you can get to an empty paragraph in LaTeX you get a first
paragraph — the one running in with the heading — containing only
horizontal white space until the end of the line, and then immediately
after a new paragraph — the actual first paragraph after the heading —
with just a normal paragraph space between it and the heading. This
probably also upsets LaTeX’s idea about what a \paragraph should be
like as little as possible.
The “manual” way to do this is as follows:
#### Level 4 heading
````{=latex}
\hfill
````
Lorem ipsum dolor sit amet.
This uses Pandoc’s relatively new raw markup syntax — the “code block”
is actually a raw LaTeX block — but it looks even more awful than the
resulting LaTeX source! It is also a tedious chore to have to insert
this after every level 4 heading. In other words you want to insert that
raw LaTeX automatically, and that can be done with a Lua filter:
--[======================================================================[
latex-h4-break.lua - Pandoc filter to get break after a level 4 heading.
Usage:
$ pandoc --lua-filter latex-h4-break.lua input.md -o output.pdf
--]======================================================================]
-- create it once, use it many times!
local hfill_block = pandoc.RawBlock('latex', '\\hfill')
function Header (elem)
if 4 == elem.level then
return { elem, hfill_block }
else -- ignore headings at other levels!
return nil
end
end
However you can also do a simple LaTeX hack in a header-includes
metadata block to get the same effect:
---
header-includes:
- |
``` {=latex}
\let\originAlParaGraph\paragraph
\renewcommand{\paragraph}[1]{\originAlParaGraph{#1} \hfill}
```
---
#### Level 4 heading
Lorem ipsum dolor sit amet.
This works by first creating an “alias” of the \paragraph command and
then redefining the \paragraph command itself, using the alias in the
new definition so that now wherever the LaTeX source created by Pandoc
contains \paragraph{Foo} it is if it instead had contained
\paragraph{Foo} \hfill which does what we want with zero extra
dependencies! (In case you wonder the wacky spelling of the “aliased”
command is to minimize the risk that it collides with anything which
already exists, since the TeX \let command doesn’t check for that. We
certainly don’t want to overwrite any existing command!)
NOTE: If you really should want more or less space than a normal
paragraph break after the heading just add an appropriate \vspace
command after the \hfill: \hfill \vspace{-0.5\parskip}.
Shifting Headers
Arguably the best way to solve this would be to avoid the problem altogether by shifting what a level 4 header corresponds to. The default for pandoc is to use \section commands for 1st level and \paragraph for 4th level headers. This can be altered via the --top-level-division parameter:
--top-level-division=[default|section|chapter|part]
Treat top-level headers as the given division type in LaTeX [...] output. The hierarchy order is part, chapter, then section; all headers are shifted such that the top-level header becomes the specified type. The default behavior is to determine the best division type via heuristics [...]
So with --top-level-division=chapter, a 4th-level header would be generated via the \subsubsection command.
Styling via LaTeX
If this is not an option, the next best way is to configure the layout of the corresponding LaTeX command: for level-four headers, this is \paragraph by default. The following methods are taken from TeX StackExchange answers.
Please also check the answer by bpj, which is much simpler than what's proposed below.
Default document-classes
The default way would be to configure \paragraph via the titlesec package. We can use the header-includes metadata field for this, which pandoc will include in the intermediate LaTeX document.
---
header-includes: |
``` {=latex}
\usepackage{titlesec}
\titlespacing*{\paragraph}{0pt}{1ex}{-\parskip}
\titleformat{\paragraph}[hang]
{\normalfont\bfseries}
{}
{0pt}
{}
```
---
KOMA document-classes
Using titlesec won't work properly for documents using KOMA classes (like scrartcl), as KOMA has it's own ways of doing things. For these, use this alternative snippet:
---
documentclass: scrartcl
header-includes: |
``` {=latex}
\makeatletter
\renewcommand\paragraph{\#startsection{paragraph}{4}{\z#}%
{-3.25ex \#plus -1ex \#minus -0.2ex}%
{0.01pt}%
{\raggedsection\normalfont\sectfont\nobreak\size#paragraph}%
}
\makeatother
```
---
I am not sure, why, but this works for me:
Put $\ \\ $ in the first line after your #### headline

pandoc not converting latex style citations correctly

I want to use latex-style citations \cite{key} in my markdown so that I can create tex and pdf documents nicely using pandoc. However, when I cite something, it shows the keyword in brackets instead of the citation style, such as author name or citation number. In other words, I want it to show up in the PDF as "This is my citation [1]" but instead it is appearing as "This is my citation [mykey]". Also, my references list isn't showing up after I add my # References header. What is going on here?
Below is my sample command for producing this along with the sample files and my current incorrect output file (test.pdf).
pandoc test.md --biblatex --biblio test.bib --csl chicago-author-date.csl -o test.pdf
test.md
% My test pandoc-ument
I want to reference this: \cite{Gepasi1993}
# References
test.bib
#ARTICLE{Gepasi1993,
Author = {P. Mendes},
Journal = {Comput. Applic. Biosci.},
Pages = {563--571},
Title = {GEPASI: A software package for modelling the dynamics, steady states and control of biochemical and other systems.},
Volume = {9},
Year = {1993}
}
test.pdf
I want to reference this: [Gepasi1993]
The --biblatex option is not for writing biblatex directly in markdown.
What it does is convert native pandoc markdown citations, like
[#Gepasil1993, p. 5]
to biblatex citations in LaTeX output.
If you use pandoc markdown citations instead of the LaTeX ones, you'll
find that the citations work. Use this command:
pandoc test.md --biblio test.bib --csl chicago-author-date.csl -o test.pdf
with this input:
I want to reference this: [#Gepasi1993]
Pandoc's citation format is documented in the Pandoc User's Guide.
If you really want to use raw biblatex citations in your markdown input,
you can, but then you need to take care of the bibliography stuff
yourself. You'd do it this way:
pandoc test.md --parse-raw -t latex -s > test.tex
pdflatex test
biber test
pdflatex test
pdfltatex test

Convert LaTeX to MediaWiki syntax

I need to convert LaTeX into MediaWiki syntax. The formulas should stay the same, but I need to transform, for example \chapter{something} into = something =.
Although this can be obtained with a bit of sed, things get a little dirty with the itemize environment, so I was wondering if a better solution can be produced.
Anything that can be useful for this task?
Pandoc should be able to do it:
$ pandoc -f latex -t mediawiki << END
> \documentclass{paper}
> \begin{document}
> \section{Heading}
>
> Hello
>
> \subsection{Sub-heading}
>
> \textbf{World}!
> \end{document}
> END
== Heading ==
Hello
=== Sub-heading ===
'''World'''!
pandoc can get your file converted between several different mark-up languages pretty easily, including mediawiki
I found this: plasTeX. With a bit of hacking probably I can produce a renderer for the mediawiki syntax
Yes Pandoc would be the easiest to do that.
pandoc -f latex -t mediawiki --metadata link-citations --bibliography=bibl.bib --csl=cslstyle.csl test.tex -o test.wiki
--metadata link-citations creates hyperlinks with your in-text citations and the bibliography. You can delete this part if not needed.
bibl.bib is the file of the bibliography you used
cslstyle.csl is the style of citation you want. There are lots of choices that can be downloaded from editor.citationstyles.org
test.tex is the file you want to convert from
test.wiki is the output file you want
all the files should be in the same folder otherwise locations should be specified

Resources