8

In my thesis I make extensive use of the exe environment of the gb4epackage and I love it. However, three of my approximately 100 examples need to have an alternative layout. Instead of the usual design I need the second and the following lines of these three examples to start where the opening bracket of the exe environment starts. So, ideally, in (1) the bdfs line and in (2) the bdfs and the cdfs line start where the opening bracket starts. Does anyone know how to locally generate this variation?

enter image description here

This is created with the following code:

\documentclass{article}

\usepackage[ngerman]{babel}%dt.Silbentrennung

\usepackage{gb4e}

\begin{document}

\begin{exe}
\ex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts
\ex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts

csdf csdf % ideally, this line starts where the opening bracket starts
\end{exe}
\end{document}

Edditional note: As Alan Munn highlighted in a comment the numbering in linguistics is continuously starting with 1. Therefore, the command / environment needs to be numbered according to its position. It has to be sensitive for previous examples and the following examples need to be sensitive to the command / environment.

Alan Munn
  • 218,180
Philip
  • 3,415

2 Answers2

11

gb4e sets the exe environment as a regular list. Moreover, every \ex macro defaults to \item (if you don't specify an optional argument). So, you can use enumitem to emulate the display, yet set some other properties as needed.

The following MWE does exactly that (I grabbed the list parameters from g4be.sty) and provides myexe as the alternative:

enter image description here

\documentclass{article}
\usepackage{gb4e,enumitem,calc}% http://ctan.org/pkg/{gb4e,enumitem,calc}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\newlist{myexe}{enumerate}{1}
\setlist[myexe]{
  label=(\arabic*),
  labelindent=*,
  leftmargin=1em,
  labelwidth=\widthof{(234)},
  labelsep=1em,
  itemindent=\labelindent+\labelwidth,
  topsep=7pt plus 2pt minus 3pt,
  itemsep=3pt plus 2pt,
  listparindent=0pt,
  parsep=1pt plus.5pt minus.5pt
  }
\makeatletter
\let\c@myexei\c@exx% http://tex.stackexchange.com/q/33898/5764
\patchcmd{\enit@enumerate@i}% <cmd>
  {\usecounter\@enumctr}% <search>
  {\@nmbrlisttrue\def\@listctr{\@enumctr}}% <replace>
  {}{}% <success><failure>
\makeatother
\begin{document}

Original \verb|exe| environment:

\begin{exe}
\ex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts
\ex asdf asdf

bsdf bsdf% ideally, this line starts where the opening bracket starts

csdf csdf % ideally, this line starts where the opening bracket starts
\end{exe}

Updated \verb|myexe| environment:

\begin{myexe}
\ex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts
\ex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts

csdf csdf % ideally, this line starts where the opening bracket starts
\end{myexe}

\end{document}

The etoolbox patch (to be placed after defining myexe) is required to make myexe fit with the rest of the exe environments used by gb4e and allows for sequential numbering of each example.

\newlist{<list>}{<type>}{<depth>} creates a list <list> that is of type <type> and has depth <depth>, almost like cloning the list. \setlist{<list>}{<options>} sets global options for the list <list> that avoid setting them locally at every usage, as in

\begin{myexe}[<options>]
  %...
\end{myexe}

For more on global list settings, see section 5 Global settings (p 9) of the enumitem documentation.

Werner
  • 603,163
  • First time I see a setlist so elaborate. This is very interesting. – azetina Nov 08 '13 at 20:47
  • 1
    @azetina: I've added some detail. – Werner Nov 08 '13 at 20:55
  • For linguists, it is essential to also add resume=exe to the keylist to continue enumeration of the examples throughout the document. – Sašo Živanović Nov 08 '13 at 21:17
  • 1
    This has the disadvantage of needing to replace all of the examples with this environment, which is not really practical. – Alan Munn Nov 08 '13 at 21:38
  • @AlanMunn: The OP mentioned that s/he has 3 out of 100 that requires a different layout. Hardly a global requirement. Moreover, if need be, one can replace exe to use myexe. I don't have enough experience with usage of g4be to advocate that. – Werner Nov 08 '13 at 21:41
  • @Werner What I meant was that to use this environment along with regular examples you need a way to harmonize the numbering, since linguistic examples are sequentially numbered throughout the document. (e.g. try the following environments in order {exe} {exe} {myexe} \item \item {exe}. The correct numbering should be (1) (2) (3) (4) (5). – Alan Munn Nov 08 '13 at 21:57
  • @AlanMunn: I think I fixed the problem... – Werner Nov 08 '13 at 22:53
  • @Werner Yes, that seems to fix it. – Alan Munn Nov 08 '13 at 23:18
  • Thanks, Werner! When I changed the labelsep to 0 it worked. But there is a minor problem. When I "built" the preamble with \usepackage{gb4e,enumitem,calc}, myexe and "the following patch" I didnt get the continuous numbering Alan Munn pointed out. Currently, myexe affects the following numbers of ´exe´, but it is not affected by ´exe´ nor by previous ´myexe´. Each ´myexe´ starts with number 1. However, ´myexe` needs to be numbered according to its position. Is there a way to make it fit, e.g. being sensitive for previous and following ´exe´ and ´myexe´ (without manual adjustment)? – Philip Nov 09 '13 at 14:09
  • @Philip: At the bottom of my answer I added the code that you need to insert in the preamble to correct for this. Did you try it? – Werner Nov 09 '13 at 14:37
  • If the counter exx is greater than 9, then the label of myexe is printed differently from its exe counterpart. I think you should delete align=left. – karlkoeller Nov 09 '13 at 16:48
  • @karlkoeller: Absolutely correct. – Werner Nov 09 '13 at 17:14
  • @Werner, somehow I missed it. Now it works. Thank you very much! – Philip Nov 10 '13 at 10:21
9

A completely different approach from Werner's one.

Load calc package and add

\makeatletter
\def\myex{\setlength{\parindent}{-\leftmargin+\labelsep}\@ifnextchar [{\@ex}{\item}}
\makeatother

in the preamble.

Then use the newly defined \myex inside the exe environments where you want the special layout, e.g.

\documentclass{article}

\usepackage[ngerman]{babel}%dt.Silbentrennung

\usepackage{gb4e,calc}

\makeatletter
\def\myex{\setlength{\parindent}{-\leftmargin+\labelsep}\@ifnextchar [{\@ex}{\item}}
\makeatother

\begin{document}

\noindent Usual layout: 
\begin{exe}
\ex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts
\ex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts

csdf csdf % ideally, this line starts where the opening bracket starts
\end{exe}

\noindent Modified layout:
\begin{exe}
\myex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts
\myex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts

csdf csdf % ideally, this line starts where the opening bracket starts
\end{exe}
\end{document} 

Output:

enter image description here

Otherwise, you can simply add a line

\setlength{\parindent}{-\leftmargin+\labelsep}

just after \begin{exe} when you want the special layout.


Of course, with this approach, items after the nineth will look like

enter image description here

If you don't like this behavior, you can substitute the above code between \makeatletter and \makeatother with the following one:

\newlength{\digitlen}
\settowidth{\digitlen}{1}

\makeatletter
\def\myex{%
\ifnum\thexnumi>8%
  \ifnum\thexnumi>98%
    \setlength{\parindent}{-\leftmargin+\labelsep-2\digitlen}%
  \else%
    \setlength{\parindent}{-\leftmargin+\labelsep-\digitlen}%
  \fi%
\else%
  \setlength{\parindent}{-\leftmargin+\labelsep}%
\fi%
\@ifnextchar [{\@ex}{\item}}
\makeatother

Thus, the following MWE

\documentclass{article}

\usepackage[ngerman]{babel}%dt.Silbentrennung

\usepackage{gb4e,calc}

\newlength{\digitlen}
\settowidth{\digitlen}{1}

\makeatletter
\def\myex{%
\ifnum\thexnumi>8%
  \ifnum\thexnumi>98%
    \setlength{\parindent}{-\leftmargin+\labelsep-2\digitlen}%
  \else%
    \setlength{\parindent}{-\leftmargin+\labelsep-\digitlen}%
  \fi%
\else%
  \setlength{\parindent}{-\leftmargin+\labelsep}%
\fi%
\@ifnextchar [{\@ex}{\item}}
\makeatother

\begin{document}

\setcounter{exx}{8}

\begin{exe}
\myex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts
\myex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts

csdf csdf % ideally, this line starts where the opening bracket starts
\end{exe}

\setcounter{exx}{98}

\begin{exe}
\myex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts
\myex asdf asdf

bsdf bsdf % ideally, this line starts where the opening bracket starts

csdf csdf % ideally, this line starts where the opening bracket starts
\end{exe}

\end{document} 

yields

enter image description here

karlkoeller
  • 124,410
  • This is a reasonable idea. It would make more sense to create a new \myex version so that you don't redefine \ex for all the other examples. – Alan Munn Nov 08 '13 at 22:05
  • @AlanMunn Indeed. I didn't read the question accurately (I was going to sleep...). I'll modify the answer. – karlkoeller Nov 09 '13 at 05:16
  • @karlkoeller, thank you so much! Your solution works perfectly well. However, the reason why I checked Werners solution is that I understand some of it (even though it is a just tiny little bit) so I can do minor adjustments myself and maybe some day I can apply it to other problems. – Philip Nov 10 '13 at 10:27