lastlegume

The site of all of the projects made by lastlegume.

20 January 2026

Restoring Clicking to go to PDF Location to Section Gradetable Exams

by lastlegume


A few months ago, I wrote a blog post about a new method I designed for creating LaTeX gradetables by section using the exam class. If you didn’t read it, it discusses the motivation and method for how I came up with this, along with an example with instructions for use. This post will do none of that, and builds upon the previous post about this method.

In the previous post, I briefly mention that the “Go to PDF location in code” feature breaks with this method, which is due to the fact that all the questions are arguments to a macro. I didn’t think much of this, but it gets annoying when the sections are multiple pages long, and I did want that to be changed. Thankfully, it’s a very easy fix. All we need to do really is remove the second argument from the command and tell the user to start a parts environment right after. parts feels wrong to write though, since this is for questions, so we can define a new environment, called anything (I chose questionsection), and tell people to start that instead. So instead of putting all the questions as arguments for the qsection command, we instead just put the title of the section as an argument and put the questions after in our custom wrapper for parts.

Here’s an example.

This effectively solves our issue, as the feature is restored, so double (or CTRL/CMD) clicking on the PDF brings the code editor to that point.

Quick copy code can be found right below this. Just like before, this goes in the preamble, and sections are created with the \qsection{Title} command with questions following in the questionsection environment.

In the preamble:

\newcounter{sectionCounter}
\newcounter{questionNumber}

\renewcommand{\thepartno}{\arabic{questionNumber}}
\renewcommand{\partlabel}{\thepartno.}

\renewcommand{\thesubpart}{\alph{subpart}}
\renewcommand{\subpartlabel}{(\thesubpart)}

\renewcommand{\thesubsubpart}{\roman{subsubpart}}
\renewcommand{\subsubpartlabel}{\thesubsubpart.}

%Fixes part spacing
\renewcommand{\partshook}{
    \setlength{\leftmargin}{0pt}
    \setlength{\labelwidth}{-\labelsep}
}

% Change \qsection to whatever name you want
\newcommand{\qsection}[1]{
    \newpage
    \stepcounter{sectionCounter} 
    \fullwidth{\section*{Section \arabic{sectionCounter}: #1}}
    
    \titledquestion{#1}
    \vspace{-2em}
}

\qformat{}
%Change \q to whatever name you want
\newcommand{\q}{
    \stepcounter{questionNumber}
    \part
}
%Change \p to whatever name you want
\newcommand{\p}{
    \subpart
}
%Change \subp to whatever name you want
\newcommand{\subp}{
    \subsubpart
}

\newenvironment{qparts}
    {\begin{subparts}}
    {\end{subparts}}

\newenvironment{qsubparts}
    {\begin{subsubparts}}
    {\end{subsubparts}}

\newenvironment{questionsection}
    {\begin{parts}}
    {\end{parts}}

Sections (outside the preamble, inside the questions environment):

\qsection{Title}
\begin{questionsection}
    % Insert questions here...
\end{questionsection}

Like last time, special thanks to this Stack Overflow post for the CSS for the LaTeX logo.

tags: latex - scioly