Error producing PDF – Latex pandoc template

errorspandoctemplates

I'm writting a pandoc template inspired on iv054-homework-template.
I want something like this:

Example

The code I use is:

\documentclass[11pt]{article}

\usepackage[T1]{fontenc}
\usepackage{titlesec}

\titleformat
{\section} % command
[display] % shape
{\normalfont\bfseries} % format
{}{\vspace{1ex}}
{Question \thesection : \ } % before-code
[\vspace{-0.5ex} \rule{\textwidth}{0.3pt}] % after-code

\begin{document}
\thispagestyle{plain}
\begin{center}
  {\Large $title$ } \\
  $author$ \\
  \today
\end{center}

$body$

\end{document}

but I get this error:

Error producing PDF.
! Undefined control sequence.
l.22 \hypertarget

what happend?

Best Answer

You just need do add the hyperref package in the preambule.

\usepackage{hyperref}

Here is the complete answer:

I created a file test.tex with the following content:

\documentclass[11pt]{article}
\usepackage{hyperref}
\usepackage[T1]{fontenc}
\usepackage{titlesec}

\titleformat{\section}[display]
  {\normalfont\bfseries}
  {}{20pt}{Question \thesection : \ }[\vspace{-0.5ex} \rule{\textwidth}{0.3pt}]

\begin{document}
\thispagestyle{plain}
\begin{center}
  {\Large $title$ } \\
  $author$ \\
  \today
\end{center}

$body$

\end{document}

and a markdown file test.md with the content:

---
title: Exam Test with Pandoc
author: Leonardo Araujo
date: November 05, 2021
---

# My test
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam mi dui, posuere vitae ligula sit amet, ultricies porta mi.

# This is a test
Duis et erat felis. Curabitur dolor diam, sagittis sed pretium at, rhoncus id sapien. Nunc sit amet ullamcorper turpis, vitae euismod nisi.

Then I compiled with

pandoc -N --template=test.tex --variable version=2.0 test.md --pdf-engine=xelatex -o test.pdf

and the result was

enter image description here