md2pdf

pandoc wrapper to convert markdown to pdf
Index Commits Files Refs README
commit 7d6be44dd746e1f3eed62ddba8907b2451f46d60
Author: mjkloeckner <martinjkloeckner@gmail.com>
Date:   Sat, 29 Apr 2023 20:20:50 -0300

first commit

Diffstat:
Amd2pdf | 34++++++++++++++++++++++++++++++++++
Astyle.tex | 177+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 211 insertions(+), 0 deletions(-)
diff --git a/md2pdf b/md2pdf
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+usage() {
+    echo "md2pdf <inputfile>"
+}
+
+[ -z "$1" ] && usage && exit 1
+
+filename=$(echo "$1" | sed 's/\.[^.]*$//')
+extension=$(echo "$1" | sed 's/^.*\.//')
+style_path="/home/mk/dox/sync/sync/md2pdf/style.tex"
+output="$filename.pdf"
+
+[ "$extension" != "md" ] && \
+    echo "Input file not markdown" && \
+    usage && exit 2
+
+# replaces ${toc} (from https://github.com/nagaozen/markdown-it-toc-done-right)
+# with \tableofcontents
+sed 's/${toc}/\\tableofcontents/' "$filename".md  |\
+pandoc --pdf-engine=xelatex \
+    -V mainfont:"Helvetica" \
+    -V colorlinks=true \
+    -V linkcolor=teal \
+    -V urlcolor=teal \
+    -V fontsize:12pt \
+    -H $style_path \
+    -f markdown+startnum+tex_math_dollars+implicit_figures+grid_tables \
+    --shift-heading-level-by=-1 \
+    -o $output
+
+[ $? -ne 0 ] && exit 3
+
+echo "generated $output successfully"
diff --git a/style.tex b/style.tex
@@ -0,0 +1,177 @@
+% \documentclass[14pt]{extarticle}
+
+% page setup
+\usepackage[a4paper,
+            top=1.5cm,
+            bottom=1.5cm,
+            left=1.25cm,
+            right=1.25cm]{geometry}
+
+\usepackage{titlesec}
+\usepackage{fontspec}
+
+% make pictures caption font bold and small
+\usepackage[font={footnotesize,bf}]{caption}
+
+% inline code (backticks in md)
+\linespread{1.10}
+\definecolor{bgcolor}{HTML}{e0e0e0}
+\let\oldtexttt\texttt
+
+\renewcommand{\texttt}[1]{
+    \colorbox{bgcolor}{\oldtexttt{#1}}
+}
+
+% change boldfont bold to extrabold
+% \setmainfont[
+%  BoldFont={Inter-ExtraBold}
+% ]{Inter}
+
+% change regular font to light font
+% \setmainfont{Inter light}
+
+\newfontfamily\titlefont{Inter}[
+UprightFont     =   *-Regular,
+BoldFont        =   *-ExtraBold,
+Scale           =   1.0
+]
+
+\newfontfamily\sectionsfont{Inter}[
+UprightFont     =   *-Regular,
+BoldFont        =   *-Bold,
+]
+
+\setmathfont{Fira Math}
+
+\usepackage{xcolor}
+\definecolor{ugrey}{HTML}{333333}
+
+\titleformat{\section}
+{\color{ugrey}\titlefont\LARGE\bfseries}
+{\color{ugrey}}
+{0em}
+{}
+
+\titleformat{\subsection}
+{\color{ugrey}\sectionsfont\Large\bfseries}
+{\color{ugrey}}
+{0em}
+{}
+
+\titleformat{\subsubsection}
+{\color{ugrey}\sectionsfont\large\bfseries}
+{\color{ugrey}}
+{0em}
+{}
+
+\titleformat{\paragraph}
+{\color{ugrey}\sectionsfont\bfseries}
+{\color{ugrey}\theparagraph}
+{0em}
+{}
+
+\titleformat{\subparagraph}
+{\color{ugrey}\normalfont\bfseries}
+{\color{ugrey}\theparagraph}
+{0em}
+{}
+
+% spacing: how to read {12pt plus 4pt minus 2pt}
+%       12pt is what we would like the spacing to be
+%       plus 4pt means that TeX can stretch it by at most 4pt
+%       minus 2pt means that TeX can shrink it by at most 2pt
+%
+% \titlespacing{command}{left spacing}{before spacing}{after spacing}[right]
+
+\titlespacing*{\section}
+{0pt}{2ex plus 1ex minus .2ex}{1.75ex plus .2ex}
+
+\titlespacing*{\subsection}
+{0pt}{1.75ex plus 1ex minus .2ex}{1.5ex plus .2ex}
+
+\titlespacing*{\subsubsection}
+{0pt}{1.5ex plus 1ex minus .2ex}{1.25ex plus .2ex}
+
+\titlespacing*{\paragraph}
+{0pt}{1.5ex plus 1ex minus .2ex}{1.0ex plus .2ex}
+
+\titlespacing*{\subparagraph}
+{0pt}{1.25ex plus 1ex minus .2ex}{1.0ex plus .2ex}
+
+% spacing between formulas and text
+\setlength{\abovedisplayskip}{5pt}
+\setlength{\belowdisplayskip}{5pt}
+
+\setlength{\abovedisplayshortskip}{9pt}
+\setlength{\belowdisplayshortskip}{9pt}
+
+\setlength{\belowdisplayshortskip}{\belowdisplayskip}
+
+\setlength{\baselineskip}{10pt}
+
+% \usepackage{setspace}
+% \setstretch{1.25}
+
+% \renewcommand{\figurename}{Fig.}
+
+\usepackage{caption}
+\captionsetup{labelformat=empty}
+
+% \renewcommand{\contentsname}{Índice}
+\renewcommand\contentsname{\vspace*{-45pt}}
+
+% TOC dots separation
+% \renewcommand{\cftdotsep}{10}
+
+% \setlength{\cftsecindent}{0pt}% Remove indent for \section
+% \setlength{\cftsubsecindent}{5pt}% Remove indent for \subsection
+% \setlength{\cftsubsubsecindent}{0pt}% Remove indent for \subsubsec
+
+\setcounter{tocdepth}{4}
+
+\usepackage{titling}
+\renewcommand{\maketitle}{ 
+    \begin{flushleft}
+    {\bfseries\Huge\thetitle}
+    \vspace{1mm}
+    \end{flushleft}
+    \thispagestyle{empty}
+}
+
+% remove the page number from all the pages that the TOC occupies
+\addtocontents{toc}{\protect\thispagestyle{empty}}
+
+% add page break after TOC set it to page number 1
+\let\oldtableofcontents\tableofcontents % remember the definition
+\renewcommand\tableofcontents{
+    \oldtableofcontents % use the standard toc
+    \thispagestyle{empty}
+    \pagebreak
+    \setcounter{page}{1}
+}
+
+% Set text color for all document
+% \color{ugrey}
+
+\usepackage[titles]{tocloft}
+\renewcommand{\cftdotsep}{1.5}
+\renewcommand{\cftsetpnumwidth}{1.5}
+\renewcommand{\cftsetrmarg}{1.5}
+
+\usepackage{float}
+\makeatletter
+\def\fps@figure{H}
+\makeatother
+
+% nicer chemichal figures
+\usepackage{chemfig}
+
+% style block quotes
+\usepackage{framed}
+\usepackage{tcolorbox}
+\let\oldquote=\quote
+\let\endoldquote=\endquote
+\renewenvironment{quote}{\begin{tcolorbox}[top=1em, bottom=1em, left=-1.5em, right=-1.5em]\begin{oldquote}}{\end{oldquote}\end{tcolorbox}}
+% end style block quotes
+
+\usepackage{nicefrac,xfrac}