2

I wish to edit the settings for pandoc that control the conversion of markdown files to LaTeX to avoid unnecessary code in the final .tex file in Ubuntu. Kindly guide me on this matter. This is my sample markdown file

Hello
$$ 
\begin{matrix}
   a & b \\
   c & d
\end{matrix}
$$

 | Syntax      |Description 
  ------------|------------
  |Header      |Title       |     
  |Paragraph   |Text        |

Here is the latex output by pandoc

\documentclass[]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
\else % if luatex or xelatex
  \ifxetex
    \usepackage{mathspec}
  \else
    \usepackage{fontspec}
  \fi
  \defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\fi
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\PassOptionsToPackage{hyphens}{url} % url is loaded by hyperref
\usepackage[unicode=true]{hyperref}
\hypersetup{
            pdfborder={0 0 0},
            breaklinks=true}
\urlstyle{same}  % don't use monospace font for urls
\usepackage{longtable,booktabs}
% Fix footnotes in tables (requires footnote package)
\IfFileExists{footnote.sty}{\usepackage{footnote}\makesavenoteenv{long table}}{}
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{0}
% Redefines (sub)paragraphs to behave more like sections
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi

% set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother


\date{}

\begin{document}

Test

Hello \[ 
\begin{matrix}
   a & b \\
   c & d
\end{matrix}
\]

\begin{longtable}[]{@{}ll@{}}
\toprule
Syntax & Description\tabularnewline
\midrule
\endhead
Header & Title\tabularnewline
Paragraph & Text\tabularnewline
\bottomrule
\end{longtable}

\end{document}

Here is the desired output

\documentclass[]{article}
\usepackage{amssymb,amsmath}
\usepackage[T1]{fontenc}
 \usepackage[utf8]{inputenc}
\usepackage[unicode=true]{hyperref}
\usepackage{longtable,booktabs}

\begin{document}

Test

Hello \[ 
\begin{matrix}
   a & b \\
   c & d
\end{matrix}
\]

\begin{longtable}[]{@{}ll@{}}
\toprule
Syntax & Description\tabularnewline
\midrule
\endhead
Header & Title\tabularnewline
Paragraph & Text\tabularnewline
\bottomrule
\end{longtable}

\end{document}

Thanks, it worked. I edited default.latex to fit my suitability, well it is noteworthy that i have to create it before i use it.

2
  • 3
    Does this answer your question? LaTeX and pandoc templates
    – Alan Munn
    Jan 17, 2020 at 14:46
  • 3
    And if not, can you make the problem a bit more specific? Can you add an example Markdown document to your question, list the output that is given by Pandoc, and describe which parts of the output you find unnecessary?
    – Marijn
    Jan 17, 2020 at 15:19

1 Answer 1

6

💡 There is a section on templates in the pandoc manual 💡


But let's get you started! Take this simple template

\documentclass[]{article}
\usepackage{amssymb,amsmath}
\usepackage[T1]{fontenc}
 \usepackage[utf8]{inputenc}
\usepackage[unicode=true]{hyperref}
\usepackage{longtable,booktabs}

\begin{document}

$body$

\end{document}

and save it as simple.latex someplace, where pandoc can find it and call pandoc with the option --template

pandoc --template=simple.latex in.md -o out.pdf

If you need more information, you can get the default template with

pandoc -D latex > default.latex
1
  • Your suggestions work great, thanks
    – neutrino
    Jan 22, 2020 at 18:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .