# “\end occurred when \ifnum ... was incomplete” with both tikz and luatexja

The following MCE:

\documentclass{article}
\usepackage{tikz}
% \usepackage{luatexja}
\begin{document}
\tikz{\coordinate[yshift=\the\ht\strutbox];}
\end{document}


compiles without anything suspect but, if the luatexja package is loaded, the .log file contains (strangely as neither a warning nor an error):

(\end occurred when \ifnum on line 25 was incomplete)
(\end occurred when \if on line 25 was incomplete)


Who is the culprit :

• the luatexja package ?
• the code tikz{\coordinate[yshift=\ht\strutbox];}, whose erroneous nature is revealed by luatexja ?

## Edit

Here is an (excerpt of an) example of failing real world usage (the real document contains reviews of both ProfCollege and hanzibox packages):

\documentclass{article}
\usepackage{ProfCollege}
\usepackage{luatexja}
\begin{document}
\Pourcentage[Calculer]{15}{39}

\verb+\hanzibox*[frametype=none]{我}[wo3][moi]\\[1ex]+
\end{document}

• See 11.5 \strutbox in the luatex-ja documentation. May 10 at 12:46
• I couldn't imagine a whole subsection of this documentation could be devoted to \strutbox :) Since \tikz{\coordinate[yshift=\the\ht\strutbox];} is part of a command of the package ProfCollege I'm using, I can't change it. I'm facing the same problem as in tex.stackexchange.com/q/643376/18401: my real document makes use of luatex-ja features only exceptionally. So, is there a way to load them only locally in order they don't interfere with other parts of the document? May 10 at 13:32
• well luatex-ja is if you skim the documentation a quite intrusive package. Are you sure you want to use it? May 10 at 13:44
• Well, not sure: it is the only solution I found for a document, compiled with lualatex, which has to display in a (single) listing (typeset in monospaced font) both Latin and Chinese characters. I load it with \usepackage{luatexja-fontspec} \ltjsetparameter{jacharrange={-9}} \setmainjfont{FandolSong}. May 10 at 13:55

This works, but the length you get is quite unpredictable, because it depends on the current text direction.

\documentclass{article}
\usepackage{tikz}
\usepackage{luatexja}
\begin{document}

\tikz{\coordinate[yshift=\the\expandafter\ht\expanded{\strutbox}];}

\end{document}


It also works when \strutbox is just a box register name, because it's unexpandable and so \expanded returns \strutbox.

In order to make this work with ProfCollege, you can patch the macros in the package that use the construction

\documentclass{article}
\usepackage{ProfCollege}
\usepackage{luatexja}
\usepackage{etoolbox}

% the abstract version of the above
\newcommand{\getstrut}[1]{%
\the\expandafter#1\expanded{\strutbox}%
}
% the internal commands of ProfCollege to patch
\patchcmd{\TikzPH}{\the\dp\strutbox}{\getstrut\dp}{}{}
\patchcmd{\TikzPHD}{\the\dp\strutbox}{\getstrut\dp}{}{}
\patchcmd{\TikzPHD}{\the\dp\strutbox}{\getstrut\dp}{}{}
\patchcmd{\TikzPB}{\the\ht\strutbox}{\getstrut\ht}{}{}
\patchcmd{\TikzPBD}{\the\ht\strutbox}{\getstrut\ht}{}{}
\patchcmd{\TikzPBD}{\the\ht\strutbox}{\getstrut\ht}{}{}
\patchcmd{\TikzRH}{\the\ht\strutbox}{\getstrut\ht}{}{}
\patchcmd{\TikzRB}{\the\dp\strutbox}{\getstrut\dp}{}{}
% the user level command to patch
\patchcmd{\FlecheLineaireH}{\ht\strutbox}{\getstrut\ht}{}{}

\begin{document}

\Pourcentage[Calculer]{15}{39}

\verb+\hanzibox*[frametype=none]{我}[wo3][moi]\\[1ex]+

\begin{center}
\Propor[
Stretch=1.25,
Math,
GrandeurA=Hauteur $h$ (cm),
GrandeurB=\begin{tabular}{c}Volume (en cm$^3$) d'un cylindre\\ de rayon \Lg{5} et
de hauteur $h$\end{tabular},
Largeur=0.75cm
]{2/$50\pi$,3/$75\pi$,5/}
\end{center}
\FlecheLineaireH{1}{2}{3}{$+$}
\FlecheLineaireB{1}{2}{3}{$+$}

\end{document}


The only user level command that uses \ht\strutbox is \FlecheLineaireH, quite strangely without \the, but I copied the example from the package documentation and it seems to work.

The previous caveat still applies: if you use different text directions as allowed by luatexja, you'll get into troubles.

• Nice! But I can't rely on this since this \tikz{\coordinate[yshift=\the\ht\strutbox];} comes from a third party package. I guess the “\end occurred when \ifnum ... was incomplete” is harmless. May 10 at 19:12
• @DenisBitouzé Ask the third party package's authors to patch. May 10 at 20:17
• Since this package is ProfCollege, devoted to French math teachers, I guess the author will consider it is not worth it. And your warning is scary :) May 10 at 20:32
• @DenisBitouzé Added the required patches May 11 at 7:57
• @DenisBitouzé This works when \strutbox has the standard meaning and, in my opinion, is better than using directly \the\ht\strutbox, but opinions may differ. May 11 at 8:43