2

MWE

\documentclass{article}

\usepackage{cleveref}
\usepackage{expex}

\begin{document}
\section{Introduction}\label{sec:intro}
\verb|ExPex| labels referred using \verb|cleveref| shows section numbers instead of example numbers.\\

\ex\label{ExPex1}
  An \verb|ExPex| example
\xe
\ex\label{ExPex2}
  Another \verb|ExPex| example
\xe
Crossref \verb|ExPex| examples using \verb|\ref{<label>}|: \ref{ExPex1} and \ref{ExPex2}\\
Crossref \verb|ExPex| examples using \verb|\cref{<label>}|: {\bf \cref{ExPex1} and \cref{ExPex2}}\\

\begin{enumerate}
\item\label{enum1} An \verb|enumerate| example
\item\label{enum2} Another \verb|enumerate| example
\end{enumerate}
Crossref \verb|enumerate| examples using \verb|\ref{<label>}|: \ref{enum1} and \ref{enum2}\\
Crossref \verb|enumerate| examples using \verb|\cref{<label>}|: \cref{enum1} and \cref{enum2}\\

\end{document}

This produces enter image description here

In the .aux file cleveref tags enumerate examples using enumi. But ExPex examples are tagged using section.

\newlabel{ExPex1}{{1}{1}}
\newlabel{ExPex1@cref}{{[section][1][]1}{[1][1][]1}}
\newlabel{ExPex2}{{2}{1}}
\newlabel{ExPex2@cref}{{[section][1][]1}{[1][1][]1}}
\newlabel{enum1}{{1}{1}}
\newlabel{enum1@cref}{{[enumi][1][]1}{[1][1][]1}}
\newlabel{enum2}{{2}{1}}
\newlabel{enum2@cref}{{[enumi][2][]2}{[1][1][]1}}

This looks similar to this question and possibly requires a fix in cleveref. Otherwise, is there a way to patch or preprend ExPex macros so that cleveref would capture their numbers?

1 Answer 1

1

From what I understand cleveref looks for the counter nearest to the label. Only LaTeX style \newcounter counters are detected, and not TeX style \newcount counters; ExPex uses \newcount. So the solution that worked is to patch ExPex's \ex to step an extra custom counter.

\usepackage{etoolbox}
\newcounter{myex}
\crefname{myex}{}{}
\creflabelformat{myex}{(#2#1#3)}
\apptocmd{\ex}{\refstepcounter{myex}}{}{}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .