Professional Documents
Culture Documents
Nnext
Nnext
Nicholas LaCara
nick.lacara@gmail.com
October 6, 2020
Abstract
This package is an add-on for the gb4e example package used in linguis-
tics. It implements the \Next, \NNext, \Last, and \LLast commands from
the linguex package or the \nextx, \anextx, \lastx, \blastx, and \bblastx
commands from the expex package. The package takes its name from the dis-
tinctively named \NNext command found in linguex.
1 Introduction
The popular linguistics example package linguex and the less popular (though
more powerful) package expex allow users to refer to previously or to-be de-
fined examples through mnemonic commands such as \Next or \nextx. The
popular package gb4e lacks any such functionality. The goal of this package is
to provide this functionality for gb4e and related packages so that users that
need (or want) to use gb4e but are more comfortable with linguex or expex can
still have access to these macros while using gb4e.
This package is currently compatible with the original gb4e package as well
as the modified version langsci-gb4e used by Language Science Press and with
gb4e-emulate by Alan Munn (which reimplements gb4e’s functionality with the
package enumitem).1
2 Usage
2.1 Loading the package
The package should be loaded in your preamble with \usepackage{nnext}.
It should be loaded after gb4e (or whichever variant you are using).
https://github.com/amunn/gb4e-emulate
1
linguex This option defines the macros \Next, \NNext, \Last, and \LLast,
as found in the linguex package. It is the default package option and does
not need to be specified.
expex This option defines the macros \nextx, \anextx, \lastx, \blastx, and
\bblastx, as found in the expex package.
noparens This option disables the use of parentheses around example num-
bers that are on by default when linguex emulation is used. This is the
typical behavior for gb4e and expex.
2.3 Macros
2.3.1 linguex emulation mode (default)
If the user loads the package with the linguex option or, indeed, with no options
specified, the package will provide the following macros.
\Next • The macro \Next will print the next example number. So, if the previous
example was (15), this will print (16).
\NNext • The macro \NNext will print the example number after next. So, if the
previous example was (15), this will print (17).
\Last • The macro \Last will print the previous example number. So, if the
previous example was (15), this will print (15).
\LLast • The macro \LLast will print the example number before last. So, if the
previous example was (15), this will print (14).
Usage of these macros is straightforward. Simply deploy them in running text,
as in the following code:
If you want to refer to the next example, type \Next.
If you want to refer to the example after that, type \NNext.
\begin{exe}
\ex[]{This is an example.}
\ex[*]{This are another example.}
\end{exe}
If you want to refer to the next example, type (1). If you want to refer
to the example after that, type (2).
If you want to refer to the previous example, type (2). If you want to
refer to the example before that, type (1).
2
2.3.2 expex emulation mode
If the user loads the package with the expex option the package will provide
the following macros.
\nextx • The macro \nextx will print the next example number. So, if the previ-
ous example was (15), this will print (16).
\anextx • The macro \anextx will print the example number after next. So, if the
previous example was (15), this will print (17).
\lastx • The macro \lastx will print the previous example number. So, if the
previous example was (15), this will print (15).
\blastx • The macro \blastx will print the example number before last. So, if the
previous example was (15), this will print (14).
\bblastx • The macro \bblastx will print the example number before last. So, if
the previous example was (15), this will print (13).
Usage of these macros is straightforward. Simply deploy them in running text,
as in the following code:
If you want to refer to the next example, type (\nextx).
If you want to refer to the example after that, type (\anextx).
\begin{exe}
\ex[]{This is an example.}
\ex[*]{This are another example.}
\end{exe}
If you want to refer to the next example, type (3). If you want to refer
to the example after that, type (4).
If you want to refer to the previous example, type (4). If you want to
refer to the example before that, type (3). If you want to refer to the
example before that, type (2).
3
the standalone class). If you have an issue, drop me an email and I’ll see if I
can’t make it work for you.
3 Rationale
This package is really just a quality-of-life add-on for people using the gb4e
example package.
The initial motivation for this package came from a colleague who needed
to typeset a document for submission to a publisher but was unable to use
linguex due to constraints imposed by the publisher’s class file. She asked
specifically if there was any way to get gb4e to replicate the functionality of
the linguex commands \Next, \NNext, and \Last, among others.
I figured it wouldn’t be too difficult to code up a solution and send it to
her (which I did!), but given that there are likely other people who, due to
various externally imposed requirements, might need to use gb4e when they
are used to another example pacakge, I thought a more robust solution might
be appropriate. This package attempts to provide that.
I also hope that this package can help people migrate to gb4e from linguex.
There are several benefits to using gb4e over linguex, including a more robust
syntax that is more aligned with standard LATEX syntax and less sensitive to code
formatting such as line-breaks. That said, gb4e is a little less user-friendly than
linguex, so I think that providing one of the features that linguex users expect
can help people to migrate if they so choose.
5 Implementation
In the following section, I present the fully commented code for the package.
5.1 Dependencies
I use the xspace package to make the spacing after example numbers right
when using the \Next, \Last, etc., commands. This mimics the behavior of
linguex.
4
1 \RequirePackage{xspace}
I also use ifthen for various booleans set by the package options.
2 \RequirePackage{ifthen}
Because this package is designed to work with a range of gb4e variants,
there is no line in the code for loading gb4e. Documents loading nnext without
loading a gb4e variant will compile will compile, but using any of the included
macros will cause an error.
5.2 Booleans
Here I define what the booleans will be. The first will set the package to
emulate linguex’s \Next, \NNext, \Last, and \LLast commands. The boolean
is set to ‘false’ initially.
3 \newboolean{emulatelinguex}
4 \setboolean{emulatelinguex}{false}
The next boolean will set the package to emulate expex’s \nextx, \lastx,
\blastx, \anextx, and \bblastx commands. The boolean is set to ‘false’
initially.
5 \newboolean{emulateexpex}
6 \setboolean{emulateexpex}{false}
The final boolean will set whether the example numbers in the text should be
set with surrounding parentheses or not. The boolean is set to ‘true’ initially.
7 \newboolean{parentheses}
8 \setboolean{parentheses}{true}
5
18 \setboolean{parentheses}{false}
19 }
After defining our package options, we tell LATEX to use linguex emulation as
the default mode.
20 \ExecuteOptions{linguex}
21 \ProcessOptions\relax
\@countername Once the right package is identified, the value of \@countername is defined to
match the counter used by that package. This allows the macros defined below
to get the current value of the example counter at any point in the document
regardless of what example package is being used.
22 \@ifpackageloaded{langsci-gb4e}%
23 {\newcommand{\@countername}{equation}}
24 {\@ifpackageloaded{gb4e-emulate}%
25 {\newcommand{\@countername}{exei}}
26 {\@ifpackageloaded{gb4e}%
27 {\newcommand{\@countername}{exx}}
28 {\PackageWarningNoLine{nnext}{No known compatible %
29 example package loaded! Examples may not be correctly %
30 referenced, or there may be fatal errors}%
31 \newcommand{\@countername}{exx}}}}%
6
5.5 Manipulating parentheses
\@lparens linguex and expex behave differently with regard to whether the output of
\@rparens reference commands include parentheses: linguex includes them; expex (like
\@afterspace gb4e) does not. The code here defines whether the macros include parentheses
based on the booleans defined above. It does this by setting the commands
\@lparens and \@rparens to either be parentheses or by defining them to be
empty. It also defines whether there should be space included after the number
(as in linguex) or not (as in expex). It does so, again, by defining the macro
afterspace to either to expand to \xspace or to exapand to nothing. These
macros are then used in the \printtmpcounter macro below.
32 \ifthenelse{\boolean{emulatelinguex}%
33 \AND \boolean{parentheses}}{%
34 \newcommand{\@lparens}{(}
35 \newcommand{\@rparens}{)}
36 \newcommand{\@afterspace}{\xspace}}{%
37 \newcommand{\@lparens}{}
38 \newcommand{\@rparens}{}
39 \newcommand{\@afterspace}{}}%
\settmpcounter Now we define the command \settmpcounter, which gets the value of the
gb4e example counter (the name of which is stored in \@countername) and
sets the value of the temporary counter to this value plus some integer:
41 \newcommand{\settmpcounter}[1]{%
42 \setcounter{tmpcounter}{\value{\@countername}}%
43 \addtocounter{tmpcounter}{#1}}
\printtmpcounter Now we define a command for printing the value of temporary counter with
or without parentheses and with or without the trailing space, depending on
whether linguex or expex is being emulated. This relies on how \@lparens,
\@rparens, and \@afterspace were defined above.
44 \newcommand{\printtmpcounter}[1]{\settmpcounter{#1}%
45 \@lparens\thetmpcounter\@rparens\@afterspace}
7
5.6.2 Generic definitions
Now we define some generic, under-the-hood macros for commands that add
to or subtract from the temporary counters and print those numbers as though
they were references. These under-the-hood commands will be assigned user-
facing names depending on whether linguex or expex is being emulated.
\@Next The macro \@Next increments the tempory counter by one, which will be the
value of the next example:
46 \newcommand{\@Next}{\printtmpcounter{1}}
\@NNext The macro \@NNext increments the tempory counter by two, which will be the
value of the example after next:
47 \newcommand{\@NNext}{\printtmpcounter{2}}
\@Last The macro \@Last does not change the value of the temporary counter, since
this is the value of the previous example:
48 \newcommand{\@Last}{\printtmpcounter{0}}
\@LLast The macro \@LLast decreases the tempory counter by one, which will be the
value of the example before last:
49 \newcommand{\@LLast}{\printtmpcounter{-1}}
\@LLLast The macro \@LLLast decreases the tempory counter by two, which will be the
value of the example before the example before last:
50 \newcommand{\@LLLast}{\printtmpcounter{-2}}
8
58 \newcommand{\anextx}{\@NNext}
59 \newcommand{\lastx}{\@Last}
60 \newcommand{\blastx}{\@LLast}
61 \newcommand{\bblastx}{\@LLLast}}{}
Index
Numbers written in italic refer to the page where the corresponding entry is
described; numbers underlined refer to the code line of the definition; num-
bers in roman refer to the code lines where the entry is used.
Symbols D \printtmpcounter
\@LLLast . . . . 50, 61 \DeclareOption . . . . . 44, 46–50
\@LLast . . 49, 55, 60 . . . . . 9, 12, 17 \ProcessOptions . 21
\@Last . . . 48, 54, 59
E R
\@NNext . . 47, 53, 58 \ExecuteOptions . 20 \relax . . . . . . . . . 21
\@Next . . . 46, 52, 57
\RequirePackage
\@afterspace . 32, 45 I
. . . . . . . . 1, 2
\@countername 22, 42 \ifthenelse . . .
\@ifpackageloaded . . . . 32, 51, 56 S
. . . . 22, 24, 26 \setboolean . . .
L
\@lparens . . . 32, 45 . . . 4, 6, 8,
\Last . . . . . . . . 2, 51
\@rparens . . . 32, 45 \lastx . . . . . . . 3, 56 10, 13–15, 18
\LLast . . . . . . . 2, 51 \setcounter . . . . 42
A \settmpcounter .
\addtocounter . . . 43 N . . . . . . 41, 44
\AND . . . . . . . . . . . 33 \newboolean . 3, 5, 7
\newcounter . . . . 40 T
\anextx . . . . . . 3, 56
\Next . . . . . .. . 2, 51 \thetmpcounter . . 45
\nextx . . . . .. . 3, 56
B V
\NNext . . . . .. . 2, 51
\bblastx . . . . . 3, 56 \value . . . . . . . . . 42
\blastx . . . . . . 3, 56 P
\boolean . . . . . . \PackageWarningNoLine X
. 32, 33, 51, 56 . . . . . . . . . 28 \xspace . . . . . . . . 36
Change History
v0.0
General: Initial version . . . . . 1