Adapting Latex class and template file to an Rmarkdown template

I'm trying to adapt an unofficial University of South Florida Latex document class and template file into an Rmarkdown template similar to the thesisdown and huskydown packages. After playing with that for a while I was able to get a package that has a custom template and can be installed with remotes::install_github("ailich/bulldown"). The document will knit, but if I add any headers to the child documents (e.g. # Chapter 1) I get the error "! Undefined control sequence. l.49 \hypertarget". Does anyone know how to fix this issue or why it would occur? I'm not very familiar with Latex so I've had trouble debugging this. I've included an example of the converted .tex document that comes out after clicking "knit" below. I've received some guidance from stackoverflow that it may be related to changing the autoidentifiers pandoc argument, but I don't understand where to put the code to change this option or how to format it.

\documentclass[boldheadings,thrmdefs,bbm,ams]{USFDissertation}

%% Set basic information about the disseration
\title{My Dissertation Title}
\author{My Name}
\degree{Doctorate of Philosopy}
\department{Marine Resource Assessment}
\college{College of Marine Science}
\university{}
\majorprofessor{your advisor}{Ph.D.}
\committeemember{committee member 1}{Ph.D.}
\committeemember{committee member 2}{Ph.D.}
\committeemember{committee member 3}{Ph.D}
\committeemember{committee member 4}{Ph.D}
\keywords{keyword1}{keyword2}{keyword3}{keyword4}{keyword5}
\approvaldate{August 5, 2023}
\copyrightdate{2023}

%% Begin the document itself
\begin{document}

%% Make a title page
\maketitle

%% Maybe dedicate it to someone
\begin{dedication}
``My dedication''
\end{dedication}
%% Acknowlege your intellectual debts
\begin{acknowledgment}
``My acknowledgments''
\end{acknowledgment}
%% Insert a table of contents
\tableofcontents

%% Insert a table of tables -- comes before figures in the format.
\listoftables

%% Insert a table of figures
\listoffigures

%% Include an abstract
\begin{abstract}
``Here is my abstract''
\end{abstract}
%% begin the body of the dissertation
\dissertation

\hypertarget{title-of-my-first-chapter}{%
\chapter{Title of my first chapter}\label{title-of-my-first-chapter}}

The first thing

The second thing

The third thing

%% End of dissertation
\end{document}

is a LaTeX error indicating that the tex object that pandoc creates from markdown is doing something untoward at its line 49, which appears to be

I can't t tell whether it's complaining about the open {% being followed by \n or if it has some other problem. But the key is to hunt down the LaTeX where hypertarget is set up and determine what it expects.

@technocrat, I'm not sure how to determine what Latex expects as neither the latex template or class files have any reference to hyperref or hypertarget. It seems to be automatically added by pandoc when referencing headers and that seems to be a problem with this particular class file.

This appears to be an open issue in pandoc. John McFarland, the principal author of pandoc considered this a tex problem and hasn't closed the issue. That leads me to think he's not going to fix the problem. In turn, that means the next step is to do an examination of the template using a tex file with your content and seeing how that renders natively. Then, come back with that file and the intermediate rmarkdown tex file and we can perhaps spot the disconnect.

Thank you @technocrat. The intermediate tex file created by the Rmarkdown file is in the example. This tex file fails to compile due to the hypertarget call, but will compile if I replace \hypertarget{title-of-my-first-chapter}{% \chapter{Title of my first chapter}\label{title-of-my-first-chapter}} with simply \chapter{Title of my first chapter}. That's why I was thinking it may be beneficial to remove the autoidentifiers all together using the pandoc_args option in bookdown::pdf_book. Included below is the tex file I'm using as a template that is being filling in with the markdown content and YAML fields.

\documentclass[boldheadings,thrmdefs,bbm,ams]{USFDissertation}

%% Set basic information about the disseration
\title{$title$}
\author{$author$}
\degree{$degree$}
\department{$department$}
\college{$college$}
\university{}
\majorprofessor{$majorprofessor$}{Ph.D.}
\committeemember{$committee1$}{Ph.D.}
\committeemember{$committee2$}{Ph.D.}
\committeemember{$committee3$}{Ph.D}
\committeemember{$committee4$}{Ph.D}
\keywords{$keyword1$}{$keyword2$}{$keyword3$}{$keyword4$}{$keyword5$}
\approvaldate{$approvaldate$}
\copyrightdate{$copyrightdate$}

%% Begin the document itself
\begin{document}

%% Make a title page
\maketitle

%% Maybe dedicate it to someone
\begin{dedication}
$dedication$
\end{dedication}

%% Acknowlege your intellectual debts
\begin{acknowledgment}
$acknowledgment$
\end{acknowledgment}

%% Insert a table of contents
\tableofcontents

%% Insert a table of tables -- comes before figures in the format.
\listoftables

%% Insert a table of figures
\listoffigures

%% Include an abstract
\begin{abstract}
$abstract$
\end{abstract}

%% begin the body of the dissertation
\dissertation

$body$

%% End of dissertation
\end{document}

I adapted this from the original template tex file which is this:

\documentclass[boldheadings,thrmdefs,bbm,ams]{USFDissertation}

%% Set basic information about the disseration
\title{Dissertation Title}
\author{Doctoral Candidate Name}
\degree{Doctorate of Philosopy}
\department{Mathematics \& Statistics}
\college{Arts and Sciences}
\university{}
\majorprofessor{Advisor Name}{Ph.D.}
\committeemember{Committee One Name}{Ph.D.}
\committeemember{Committee Two Name}{Ph.D.}
\committeemember{Committee Three Name}{Ph.D}
\chair{Committee Chair Name}{Ph.D}
\keywords{KeyWordOne}{Key Word Two}{KeyWord Three}{Key WordFour}{KeyWordFive}
\approvaldate{Month Day, Year}
\copyrightdate{Year}

%% Include whatever macros you like
%% Some people like these:
% \def\beq{\begin{equation}}
% \def\eeq{\end{equation}}

%% Begin the document itself
\begin{document}

%% Make a title page
\maketitle

%% Maybe dedicate it to someone
\begin{dedication}
Tx xxx xxxxx xxx xxxxxx xx xxxxxxxxxx xxxx xxx Fxxxxxxx Dxxxx Txxxxxx xxxxxxx xxxx xx xxx xxxxx xx xxxxxxx xxxxxxx.
\end{dedication}

%% Acknowlege your intellectual debts
\begin{acknowledgment}
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxx xx X. Xxxxxxxx, xxxxx xxxx xxx xx xxxxxxx
xxxxxxxxx, xxx.
\end{acknowledgment}

%% Insert a table of contents
\tableofcontents

%% Insert a table of tables -- comes before figures in the format.
\listoftables

%% Insert a table of figures
\listoffigures

%% Include an abstract
\begin{abstract}
Lxxx xx xxxxxx xxxxxx'x xxxxxx xxx xxx xx xx xxxxxxxxxxx xx xxxx xx
\[x_{x=1}^{xxxxx}x{1}{x^x}=x(x)=0,\]
xxxx $R(x) = x{1}{2}$.
Txxx I xxxx xxxxx xxxx xx xxxxxx xxxx-xxxxxx xxxxxxx xxxxx xx xxxx
xxxx xxxx xxx xxxxxxx xxxx xxxx x xxxxx xxxx xx Exxxx'x.
\end{abstract}

%% begin the body of the dissertation
\dissertation

%% Chapter One:
\chapter{First Chapter Name}
Txxx I xxxx xxxxx xxxx xx xxxxxx xxxx-xxxxxx xxxxxxx xxxxx xx xxxx

%% Chapter One, Section One:
\section{First Section Name}
Txxx I xxxx xxxxx xxxx xx xxxxxx xxxx-xxxxxx xxxxxxx xxxxx xx xxxx

%% Chapter One, Section One, Subsection One:
\subsection{First Subsection Name}
Txxx I xxxx xxxxx xxxx xx xxxxxx xxxx-xxxxxx xxxxxxx xxxxx xx xxxx

%% Chapter One, Section One, Subsection One, Subsubsection One:
\subsubsection{First Subsubsection Name}
Txxx I xxxx xxxxx xxxx xx xxxxxx xxxx-xxxxxx xxxxxxx xxxxx xx xxxx.
%% Reference to table
See Table \ref{table:1} on page \pageref{table:1}
%% Citation
\cite{PXX}.


%% Figure One:
\begin{figure}
% \begin{center}
% \includegraphics{}{}
% \end{center}
\caption{First Figure Caption}
\end{figure}

%% Chapter Two
\chapter{Second Chapter Name}

%% Table One:
\begin{table}[h!]
\begin{center}
\begin{tabular}{c|c|c}
First Column&Second Column&Third Column\\
Second Row& etc. & etc.\\
Third Row & etc. & etc.
\end{tabular}
\end{center}
\label{table:1}
\caption{First Table Caption}
\end{table}

%% Figure Two:
\begin{figure}
\caption{Second Figure Caption}
\end{figure}

%% Chapter Three:
\chapter{Third Chapter Name}

%% Chapter Three, Section One:
\section{First subsection in chapter three.}

%% Theorem and proof -- using theorem-like environments from thrmdefs

\begin{theorem}
Ix $R(x)>0$, xxxx $x(x)=0$ xxxxxxx \[R_x=x{1}{2}.\]
\end{theorem}

\begin{proof}
Ix $R_x x>0$, xxxx $\sin(x)=0$ xxxxxxx \[R_x=\frac{1}{2}.\]
\end{proof}

%% Table Two:
\begin{table}[h!]
\begin{center}
\begin{tabular}{c|c|c}
First Column&Second Column&Third Column\\
Second Row& etc. & etc.\\
Third Row & etc. & etc.
\end{tabular}
\end{center}
\label{table:2}
\caption{Second Table Caption, xxxxxxxxx xxx xxxxxxxx xxxx xxxxxxxxxxx xxxx xxxxxxxx \hspace*{.25in} xx xxxxxxx}
\end{table}

%% Table Three:
\begin{table}[h!]
\begin{center}
\begin{tabular}{c|c|c}
First Column&Second Column&Third Column\\
Second Row& etc. & etc.\\
Third Row & etc. & etc.
\end{tabular}
\end{center}
\label{table:3}
\caption{Third Table Caption}
\end{table}

%% Reference section
\begin{thebibliography}{99}
\bibitem{PXX}X. X. Xxxxxxx. ``Xxxxx xxx xxx xx xxxx.'' \emph{Xxx Xxxxx}, \textbf{123}, 4567  
\end{thebibliography}

%% About the author
\begin{bio}
Bxxx xx xxx xxxxx xx Txxxxxxx, I. Txxx Yxxxx xxxx xxxx xx xxxxx
xxx xxxx xxx xxx xxxxxxxx xx xxxxx xxx Rxxxxxx xxxxxxxxxx. Sxx
xxxxxxxx xxxxxxx xx xxxxxxx xxxxxx, xxx xx xxxx xxxxxxxxxxxx
xxx xxxxx xxxxx xxxx xxxx-xxxxxx xxxxxxx. Dxx xx xxx xxxx xxxxxx
xxxxxxxx, xxx xxxxxxxxx xxxx xx xxxxxxxxxxxxxxxx xxxxxxxxxxxx,
xx xxxx xx-xxx xxxx xxxxx xxxxxx xx xxx xxxxxx xxx xxxxxxxxx
xx xxx xxxxx xxxxx.
\end{bio}

%% End of dissertation
\end{document}

Great. If it were me doing this and I had no urgent need to go deeper, I would take the intermediate file and run it through a shell filter

$ sed -e 's/^.hypertext.*label/\.chapter/' the_tex 

Thank you @technocrat. I would like to make the document as easy as possible because I plan to share the template with others, so I did dig a bit deeper and stumbled on a different stack overflow post. It provided an example for specifying the YAML version and from that I was able to work out the sytax for within bookdown::pdf_book. Either of the code options below fixes the hypertarget issue!

output: 
  bulldown::thesis_pdf:
    pandoc_args: [
      "-r", "markdown-auto_identifiers"
      ]

pandoc_args = c(pandoc_args, "--top-level-division=chapter", "-r","markdown-auto_identifiers")

Additionally, the method using the md_extensions YAML field posted below by cderv works as well!

1 Like

@ailich

I did not read about all the issue but know that pdf_document() has a md_extensions argument to pass specific extensions as you did

output: 
  bulldown::thesis_pdf:
    md_extensions: -auto_identifiers

should work if you want to deactivate the auto identifier.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.