Set double spacing and line numbers when converting from Markdown to PDF with pandoc - latex

I am using markdown & pandoc for scientific writing, I know I can change margins of the final pdf using
Set margin size when converting from Markdown to PDF with pandoc
but very often the journals require double lines and line numbers in submitted manuscripts, the question is how to change these, I don't know much about LaTex so I am lost in that jungle.
Thanks!

In more recent version of Pandoc, you can use a YAML header and include a bunch of metadata in that, instead of using options on the command line. So, for instance, you can put this at the top of your .md file:
---
title: The Document Title
author:
- Your Name
- Co Author
date: \today{}
geometry: margin=2cm
header-includes:
- \usepackage{setspace}
- \doublespacing
- \usepackage{lineno}
- \linenumbers
---
Document Text
and pandoc will read those options and apply them automatically.

There is maybe an easy way: generate a file with the packages we need
\usepackage{setspace}
\doublespacing
\usepackage[vmargin=1in,hmargin=1in]{geometry}
\usepackage{lineno}
\linenumbers
I named it options.sty. And use the -H FILE option that includes the content of the FILE at the end of the preamble. (as used in https://github.com/karthikram/smb_git)
pandoc -H options.sty --bibliography mypaper.bib mypaper.md -o mypaper.pdf
The advantage is that we don't need to edit the template. To add linenumbers, change margins, and set spacing it works.

You'll need to use a custom LaTeX template. First, use pandoc to create a copy of the default template:
pandoc -D latex > mytemplate.latex
Now edit this template. Somewhere in the preamble (between \documentclass{...} and \begin{document}), insert the lines
\usepackage{setspace}
\doublespacing
Then, to use your custom template:
pandoc --template mytemplate.latex mypaper.txt -o mypaper.tex

Related

Export tex document which uses the exam class (Part 2)

I would like to export a text document which uses the exam class to markdown. To do so, I am currently using a workaround which was suggested in this answer, which relies on pseudo-definitions which in turn overwrite the definitions of the exam class such that pandoc can produce a clean markdown file.
Although, the workaround works for the suggested multiple-choice questions, I cannot adopt the solution to work for text with “fillin gaps” such as the document below:
\documentclass[answers]{exam}
\usepackage{minted}
\let\oldpart\part
\renewcommand{\part}[1][]{\oldpart[#1]{}}
\begin{document}
\begin{questions}
\question Exercise 1
\begin{parts}
\part[1] This fills in the \fillin[blanks][3cm]
\end{parts}
\end{questions}
\end{document}
If I use the following pseudo-definitions in a separate file:
% ignore \part
\renewcommand{\part}[0][1]{}
% Treat checkboxes like an itemized list
\newenvironment{checkboxes}{\begin{itemize}}{\end{itemize}}
\renewcommand{\CorrectChoice}{\item ☒ }
\renewcommand{\choice}{\item ☐ }
\renewcommand\fillin[2][{}]{\textbf{#1}}
I get the following broken markdown output
This fills in the **blanks**3cm\]
Moreover is there a way for pandoc to ignore \begin{parts} and \end{parts} so that there are no ::: in the final Markdown file?
The \fillin problem can be solved with
\newcommand{\fillin}[1][1]{\textbf{#1}\noop}
whereas the parts div can be removed with
\newenvironment{parts}{}{}

How do I specify a subparagraph in RMarkdown?

I am trying to type text in RMarkdown for a PDF document with a subparagraph in the text.
It uses a template which defines the titlesec subparagraph style, but I can't get the \subparagraph{...} command through to LaTeX unmangled. It produces \textbackslash subparagraph\{...\}
I put subparagraph: true in the YAML header.
What is the correct syntax for the subparagraph text block, or is there a special symbol like ## for sections?
Found the secret code in Pandoc documentation - it is ######

Modify latex template in Rmarkdown

Can I modify the default Latex template used by Rmarkdown to compile Rmd files to pdf with the beamer class?
I am asking because of the difficulties I encounter using \includepdf (from the pdfpages package). Inspecting the generated tex source suggests that the root problem is the ignorenonframetext option in \documentclass[ignorenonframetext,]{beamer}.
(It is not a viable option for me to manually change the tex source each time)
In short: I want to modify the "Rmd beamer Latex template" (if that exists) to change the default ignorenonframetext
You don't need to modify the template, you can use \includepdf like this:
---
output:
beamer_presentation:
keep_tex: true
header-includes:
- \usepackage{pdfpages}
- \setbeamercolor{background canvas}{bg=}
- \makeatletter\beamer#ignorenonframefalse\makeatother
---
test
``` {=latex}
\end{frame}
\includepdf[pages=1-10]{example-image-duck}
\begin{frame}
```
test
(the line \setbeamercolor{background canvas}{bg=} is necessary for beamer versions < 3.64, a patch has been added in 9e3bb9)

Add project brief in Doxygen LateX output

How do I add the PROJECT_BRIEF that I defined in the Doxyfile to the LaTeX output? I want it to appear just bellow the project title.
I have tried using
/ref{$projectname}
and
/ref{$projectbrief}
as explained in the doxygen manual, in the LATEX_HEADER section, but it just displays as ??.
In the current version (1.8.13) of doxygen this is not directly possible.
doxygen has the possibility to use a dedicated header, option LATEX_HEADER in the doxygen configuration file. By generating a default header (doxygen -w latex <header> <footer> <stylesheet>), modifying the <header> and using the modified <header> it is possible to accomplish the required functionality.
In the default you will find the line:
{\Large Your title here}\\
replace this with e.g.:
{\Large {$projectname} \\[1ex]\large {$projectnumber} \\[1ex]\large {$projectbrief} }\\
The [1ex] gives some extra vertical spacing between project* items

Define Latex packages in reST file

We used Docutils to produce reST document, and then make a TeX file via rst2latex.
In the rst file, we have added a lot of LaTeX code like:
.. raw:: latex
~\\
\rule{\textwidth}{1pt}
~\\
But I do not know where to add packages like \usepackage{tabulary}.
If I add it in the rst file like I've shown above, even in the very beginning, this \usepackage line is automatically added after \begin{document} in the tex output file. This obviously generates an error.
Any idea where can I add \usepackage commands in reST?
You can use the LaTeX preamble (after Docutils 0.7) by
rst2latex foo.rst foo.tex --latex-preamble="\usepackage{tabulary}"
which will generate the following in foo.html
%%% Custom LaTeX preamble
\usepackage{tabulary}
Alternatively, a custom stylesheet can be provided by
rst2latex foo.rst foo.tex --stylesheet=preamble.tex
which will generate
%%% User specified packages and stylesheets
\input{preamble.tex}
in the right place.

Resources