# \linewidth in expex

It seems to me that examples in expex have no effect on the length of \linewidth, which is especially annoying if you want to put two things next to each other with a minipage, or you include a table.

I have already found out about the existence of zref-abspos, however, the values I get from this are also strange, and tabu doesn't seem to heed them anyway for some reason. Here is a MWE:

\documentclass{article}
\usepackage{expex}
\usepackage{lipsum}
\usepackage{tabu}
\usepackage{zref-abspos}
\newlength{\remaining}
\newcommand{\remain}[1]{%
\zsavepos{#1}%
\setlength{\remaining}{\linewidth minus \zposx{#1}sp}%
}
\begin{document}
The linewidth: \the\linewidth. \lipsum[1]
\pex
\a \remain{test}%
\begin{tabu} to \linewidth {| X | X |}
\hline
Linewidth & \the\linewidth \\
\hline
\end{tabu}
\a \begin{tabu} to \remaining {| X | X |}
\hline
Remaining & \the\remaining \\
\hline
\end{tabu}
\xe

\begin{itemize}
\item Linewidth: \the\linewidth
\begin{itemize}
\item Linewidth: \the\linewidth
\end{itemize}
\end{itemize}
\end{document}


This is what I get when I try to calculate the distance between the example text and the left page margin. expex doesn't seem to provide this distance as a length, at least the documentation doesn't mention it explicitly, only numoffset (distance between page margin and example number) and textoffset (distance between example number and text). 174pt seems way too much, however, since the text even for the second-level bullet point is just 47.0003pt in.

It also does not seem to be possible to access the indentation length for examples with enumitem's textoffset.

• It's not clear what you try to do here but minus does not subtract the two lengths, which I think might be the intention. – David Carlisle Jun 23 '17 at 20:51
• I seem to have gotten confused there by LaTeX returning \the\lengths in this format – Jipí Jun 23 '17 at 22:43
• the syntax is legal but it isn't subtraction a length of 5pt plus 2pt minus 1pt is a stretchy length with natural size 5pt which can shrink to 4pt and stretch to 7pt. to do 5pt - 1pt use \dimexpr 5pt - 1pt \relax. – David Carlisle Jun 23 '17 at 22:57

I'm assuming you want to be able to add tables which take up the space remaining in the ExPex example line. ExPex doesn't use LaTeX list constructs to build the enumerations, so as you observe, \linewidth is not a parameter that is updated by ExPex. So you are right that you need to calculate the remaining space. To do this you need to use the lengths that ExPex uses in its construction of the example numbers.

Two calculations are needed, depending on whether the example is an \ex example or a \pex example. To make things simple, I've used etoolbox to prepend the calculation automatically, so that the \remaining value is calculated for every example. I've used the showframe option of geometry to show that the calculation is correct. For testing purposes I've repeated both types of examples using pgffor to show different example numbers.

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{expex}
\usepackage{tabu}
\usepackage{calc}
\usepackage{etoolbox}
\usepackage{pgffor}
\newlength{\remaining}

\newcommand{\remainpex}{%
\setlength{\remaining}{\linewidth-\lingtextoffset-\linglabelwidth-
\lingnumoffset-\linglabeloffset-\widthof{\exnoprint}}%
}
\newcommand{\remainex}{%
\setlength{\remaining}{\linewidth-\lingnumoffset-
\lingtextoffset-\widthof{\exnoprint}}%
}
\pretocmd{\pex}{\remainpex}{}{}
\pretocmd{\ex}{\remainex}{}{}
\begin{document}
\foreach \x in {1,10,100}{
\excnt=\x
\pex
\a %
%
\begin{tabu} to \remaining {| X | X |}
\hline
sometext & sometext \\
\hline
\end{tabu}
\a \begin{tabu} to \remaining {| X | X |}
\hline
sometext & sometext \\
\hline
\end{tabu}
\xe
\ex
\begin{tabu} to \remaining {| X | X |}
\hline
sometext & sometext \\
\hline
\end{tabu}
\xe
}
\end{document}