Pandoc LaTeX shopping list template

2021-01-05

I wanted to be able to create a printable shopping list with nice formatting, mainly as an exercise in practicing Pandoc templating, but also maybe to try and automate some of the recurring struggles with buying enough groceries and the correct items. Here is the LaTeX template:

\documentclass[a4paper, 12pt, twocolumn]{article}

% Language
\usepackage[utf8]{inputenc}
\usepackage[UKenglish]{babel}

% List items with boxes
\usepackage{enumitem}
\usepackage{amssymb}
\renewcommand{\labelitemi}{$$\Box$$}
\renewcommand{\labelitemii}{$$\Box$$}
\renewcommand{\labelitemiii}{$$\Box$$}

% Page geometry
\usepackage{geometry}
\geometry{left=2.2cm,
	right=2.2cm,
	top=1.5cm,
	bottom=2cm}

% Pandoc specific
\usepackage{hyperref}

\providecommand{\tightlist}{
	\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}
}

% Title 
\makeatletter
\renewcommand{\maketitle}{\bgroup\setlength{\parindent}{0pt}
\begin{flushleft}
  	\textbf{\large{\@title}}\\
	\@date\\
	\rule{\textwidth}{1pt}
\end{flushleft}\egroup
}
\makeatother

% Section titles
\usepackage{titlesec}

\titleformat{\section}
  {\large\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}
  {\normalfont\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}
  {\normalfont\itshape}{\thesubsubsection}{1em}{}

%\titlespacing{command}{left spacing}{before spacing}{after spacing}[right]
\titlespacing\section{0pt}{12pt}{4pt}
\titlespacing\subsection{0pt}{14pt}{4pt}
\titlespacing\subsubsection{0pt}{14pt}{4pt}

% Prevent section breaking across pages (columns)
\let\oldsection\section
\renewcommand{\section}{
\filbreak
\oldsection
}

% Text formatting
\setcounter{secnumdepth}{0}  % Remove section numbers
\pagenumbering{gobble}  % Remove page numbers
\setlength{\parindent}{0pt}  % Stop indenting paragraphs

% Pandoc arguments
$if(title)$
\title{$title$}
$else$
\title{Shopping List}
$endif$

$if(date)$
\date{$date$}
$else$
\date{\today}
$endif$

\begin{document}
\twocolumn[\maketitle{}]

$body$

\end{document}

Key features are a redefined title section so it doesn’t take up so much space, tickable boxes instead of bullet points, and some trickery with the section headings so they take up less space, and so that a section never breaks across two columns or pages.

Example shopping list