2

I use \usepackage{gb4e} to reference and to contiuously number my linguistic examples.

It works like this:

\documentclass{article}

\usepackage[ngerman]{babel}
\usepackage{gb4e}

\begin{document}

\section{Introduction} \label{intro}

\begin{exe}
\ex \label{a} asdf
\end{exe}

In \ref{a} \dots. In \ref{intro} \dots.

\end{document}

The output looks like this:

enter image description here

Ideally, the \ref{a} output of the exe environment would be displayed in brackets while references of other elements like \section will still be shown without brackets. So the output would look like this:

enter image description here

Is anyone there who can solve the problem globally?

Note: I try to avoid to add brackets manually and write (\ref{}) in the tex file.

  • 1
    By "brackets" you mean parenthesis, right? – Sverre Nov 12 '14 at 18:09
3

Define a new command. Below I've called it \pref (short for parenthesis ref):

\documentclass{article}
\usepackage{gb4e}
\newcommand{\pref}[1]{(\ref{#1})}

\begin{document}
\section{Introduction} \label{intro}
\begin{exe}
    \ex \label{a} asdf
\end{exe}
In \pref{a} \dots. In \ref{intro} \dots.
\end{document}

enter image description here

  • To be fair, I've stolen this code from somewhere, but I don't remember where. Maybe here. – Sverre Nov 12 '14 at 18:14
  • Sverre, thank you so much. The attempt is slightly more elegant than the (\ref{}) but it involves a lot of manual replacing still. I was hoping for a solution that will treat the ref{}differently in case it refers to the exe environment. – Philip Nov 13 '14 at 8:38
  • @Philip How does it involve a lot of manual replacing? You still need to type \ref{...} when you want a reference, so I don't see how it's any harder to type \pref{}? If necessary, define it as \pef. Then it's exactly the same number of characters. – Sverre Nov 13 '14 at 11:52
  • thank you for your comment. I would like to use the command for larger documents that are already existing. So in these documents it would be necessary to search for each \ref{} manually and replace it if it is a exe \ref{}. For future documents it doesnt mean manual adjustment. – Philip Nov 13 '14 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.