4

How to refer to selected linguex example numbers without parentheses? The editors want me not to use parentheses around example numbers that are placed within parentheses in the text. Like in the following example:

\documentclass{minimal}
\usepackage{linguex}
   %\renewcommand{\theExLBr}{} %removes the left bracket in examples
   %\renewcommand{\theExRBr}{} %removes the right bracket in examples

\begin{document}

 \ex. example A\label{A}

 \ex. example B\label{B}

 \textbf{Required:} example in \ref{A} (and example in 2).\\
 \textbf{Unacceptable:} example in \ref{A} (and example in \ref{B}).

\end{document}

enter image description here

Defining it globally with the \theExLBr & \theExRBr commands (unselected in the MWE above) and adding parentheses only to examples like (1) in the MWE is a very uncomfortable option (there's hundreds of examples like (1) and few examples like 2 in the manuscript). So, I was thinking about a way of suppressing () around selected examples. Can I perhaps somehow use \theExLBr & \theExRBr commands for individual examples (that would essentially give the desired result) or something similar in effect? The file must be generated with XeLaTeX.

1 Answer 1

5

Since TeX has no way of knowing if you're inside parentheses or not, you need a new command for a reference inside parentheses which will "remove" the extra parentheses. We'll call this command \pref which is just like \ref but will not have parentheses around the number. But since it's easier to add things than remove them, we'll redefine the \ExNoLBr and \ExNoRBr to add the parentheses conditionally. Since labels are written to the .aux file, we need to protect these commands from being expanded there so that the conditional can do its magic when the reference is resolved.

\documentclass{article}
\usepackage{linguex}
\newif\ifparens\parensfalse
\makeatletter
\renewcommand{\theExNo}{\protect\theExLBr\arabic{ExNo}\protect\theExRBr}
\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
\renewcommand\theExLBr{\ifparens\else(\fi}
\renewcommand\theExRBr{\ifparens\else)\fi}
\newcommand\pref[1]{{\parenstrue\ref{#1}}}

\begin{document}

 \ex. example A\label{A}

 \ex. example B\label{B}

 \textbf{Required:} example in \ref{A} (and example in 2).\\
      \textbf{Now acceptable:} example in \ref{A} (and example in \pref{B}). Subexamples \ref{A:sub} (like this one \pref{A:sub}) also work.


\end{document}

output of code

3
  • 2
    @oliver See edit. You need an extra pair of braces around the definition of \pref so that the conditional isn't set globally.
    – Alan Munn
    Commented Apr 28, 2019 at 21:35
  • 1
    Correct! Excellent, thanks!
    – oliver
    Commented Apr 28, 2019 at 23:14
  • or simply keep \ref always without parentheses as given in the answer and use \eqref Commented Aug 31, 2022 at 22:30

You must log in to answer this question.

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