1

I am using the linguex package that can index sentences throughout the document automatically. However, very often, I will need to add example sentences, which will change the indices of all the sentences after the one inserted. Therefore, I am wondering how I can retrieve the index of a certain sentence so that I won't have to manually change the indices in the paragraph after inserting new example sentences.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{linguex}

\begin{document}

\ex. This is a sentence.\par \ex. This is another sentence.\par For example, I want to know how to retrieve the index of the second sentence, which is ``(2)," without entering it manually.

\end{document}

enter image description here

moewe
  • 175,683
FSY
  • 33

1 Answers1

1

Use \label and \ref. Most things that LaTeX numbers can be referred to with \ref if you set a \label in the right place.

Generally speaking, the \label needs to go after the command that produces the numbering (sometimes it can also go in the argument of that command), then the \label{<labelname>} can be referred to from any point in the document body with \ref{<labelname>}.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{linguex}

\begin{document}

\ex. \label{ex:a}This is a sentence.\par \ex. \label{ex:another}This is another sentence.\par

Blorb \ref{ex:another} and \ref{ex:a}

\end{document}

Blorb (2) and (1)

Most LaTeX introductions will touch on \label and \ref. If you want more examples, have a look at https://www.learnlatex.org/en/lesson-09 or your favourite LaTeX introduction/tutorial.

A nice explanation of LaTeX's cross-referencing mechanism that explains the technical side of things, but also comes with simple use examples, can be found in Understanding how references and labels work.


The linguex documentation (which you can open with texdoc linguex on your computer) says the following about cross references (p. 2)

Cross reference can be handled by \label{...} and \ref{...} in the usual manner. For example, a label between \ex. and \a. stores the main example number for further reference; the same command following \a. or \b. stores the label of a (sub-)subexample for further reference.

For cross references in the immediate vicinity of an example, you need not \label the examples. \Next refers to the following example number, and \NNext to the next but one. Reference to the previous example is provided by \Last; the penultimate one is referred to with \LLast

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{linguex}

\begin{document} Lorem \Next and \ref{ex:another}

\ex. \label{ex:a}This is a sentence.\par \ex. \label{ex:another}This is another sentence.\par

Ipsum \Last and \ref{ex:a}

Blorb \ref{ex:another} and \ref{ex:a} \end{document}

But for consistency with how most other cross references work and to be absolutely sure all references refer to the exact thing you think they refer to, it is probably safest to stick with \label+\ref.

moewe
  • 175,683