3

This is a follow up to the question (and the answer) here.

I have the same issue as OP, in that I cannot use parentheses around example numbers that are placed within parentheses in the text. Unlike OP, I also have references to subexamples. I tried using the original code:

\documentclass{minimal}
\usepackage{linguex}
\newif\ifparens\parensfalse
\renewcommand{\theExNo}{\protect\theExLBr\arabic{ExNo}\protect\theExRBr}
\renewcommand\theExLBr{\ifparens\else(\fi}
\renewcommand\theExRBr{\ifparens\else)\fi}
\newcommand\pref[1]{{\parenstrue\ref{#1}}}
\begin{document}

\ex. \label{ex:1} \a. \label{ex:2}Look, an example!
\b. \label{ex:3}And there's another one!

%\pref{ex:1},
\pref{ex:2}, \pref{ex:3},

\ref{ex:1}, \ref{ex:2}, \ref{ex:3}


\end{document}

I get this output:

As you can see, the \pref{} command still leaves the parentheses around the number if there is a sublevel involved, and furthermore, it introduces a linebreak with a big vertical space. The linebreak disappears if I comment out \pref{ex:1} below, but the parentheses remain.

I haven't been able to figure out how I could make \pref{} fully general, so that it works for crossreferences to any level. Is there a way to do so?

I am aware that I could make the crossreference to the full example, and add the reference to the subexample manually (as in \pref{ex:1}a), but this would break the links, and I would like to avoid this. Otherwise, I could probably redefine away the opening and closing parentheses entirely (as suggested in an answer to OP), and then use \eqref{} for the normal cases, and reserve \ref{} for occurrences in parentheses. However, with colored links and hyperref, the parentheses are visibly not part of the link – which I would also like to avoid.

1 Answer 1

3

For the general solution, the two variables \theSubExNo and \theSubSubExNo also need to be redefined, before defining \pref{}.

The only change that is necessary is to protect the variables \theExLBr and \theExRBr. For reference, here is a MWE:

\documentclass{article}
\usepackage{linguex}

\makeatletter
\newif\ifparens\parensfalse
\renewcommand{\theExNo}{\protect\theExLBr\arabic{ExNo}\protect\theExRBr}
\renewcommand\theExLBr{\ifparens\else(\fi}
\renewcommand\theExRBr{\ifparens\else)\fi}
\renewcommand{\theSubExNo}{%
  \hbox{\if@noftnote\protect\theExLBr\Exarabic{ExNo}\firstrefdash
      \Exalph{SubExNo}\protect\theExRBr
    \else
      \protect\theFnExLBr\Exroman{FnExNo}\firstrefdash%
      \Exalph{SubExNo}\protect\theFnExRBr
    \fi}}

\renewcommand{\theSubSubExNo}{%
  \hbox{\if@noftnote\protect\theExLBr%
          \Exarabic{ExNo}\firstrefdash\Exalph{SubExNo}\secondrefdash
             \Exroman{SubSubExNo}\protect\theExRBr%
    \else\protect\theFnExLBr\Exroman{FnExNo}\firstrefdash
              \Exalph{SubExNo}\secondrefdash\Exarabic{SubSubExNo}\protect\theFnExRBr\fi}}%
\makeatother

\newcommand\pref[1]{{\parenstrue\ref{#1}}}

\begin{document}

\ex. \label{ex:1} \a. \label{ex:2}Look, an example!
\b. \label{ex:3}And there's another one!

This is the solution (look at the total absence of parentheses in \pref{ex:1}, \pref{ex:2}, and \pref{ex:3})!


And here are the normal references: \ref{ex:1}, \ref{ex:2}, and \ref{ex:3}.

\end{document}

Here is the output:

enter image description here

Edit: Changed minimal class to article as suggested by Alan Munn.

3
  • 1
    Please don't use minimal as a document class. Despite its name, it is not a class designed for minimal examples. Use article instead. Thanks for bringing up the issue. I'll update the linked answer (since I should have included those cases originally).
    – Alan Munn
    Feb 23 at 15:27
  • Thank you for your answer – it got me started! I've changed the document class. Is there any chance this functionality could be added to the original package? Feb 23 at 15:46
  • 1
    I doubt it. The author has been retired for a number of years and I don't think he has much interest in the package any more. Personally I don't like the package myself, since it's very unstructured markup which makes it harder to hook into. I suspect for this reason that it will be harder to adapt to tagging code for making documents accessible.
    – Alan Munn
    Feb 23 at 16:21

You must log in to answer this question.

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