8

Indeed, the following macro \NewDocumentCommand{\xsameword}{m} written by @nox in his answer here, has a compile-time error.

! Missing \endcsname inserted.
<to be read again> 
                   :
l.74 \end{frame}

An excerpt from the log (which I hope is well chosen) with the LaTeX3 command \errorcontextlines=5 as requested by @DonHosek

! Missing \endcsname inserted.
<to be read again> 
                   :
\l__regex_internal_a_tl ...word_format\exp_not:N :
                                                  n\cs_end: \exp_after:wN {\...
<argument> ...}\fi: }\fi: \l__regex_internal_a_tl 
                                                  \if_int_compare:w \l__rege...

\use:x ...cs_set_nopar:Npx \l__exp_internal_tl {#1 }\l__exp_internal_tl __maieul_xsameword_start:n ..._xsameword_list_tl \tl_use:N \l__maieul_xsame...

\beamer@doifinframe ...té d'aire est appelée le} \keepword {\og \textit {... ... l.74 \end{frame}

The control sequence marked <to be read again> should not appear between \csname and \endcsname.

! Missing \endcsname inserted. <to be read again> : \l__regex_internal_a_tl ...word_format\exp_not:N : n\cs_end: \exp_after:wN {... <argument> ...}\fi: }\fi: \l__regex_internal_a_tl \if_int_compare:w \l__rege...

\use:x ...cs_set_nopar:Npx \l__exp_internal_tl {#1 }\l__exp_internal_tl __maieul_xsameword_start:n ..._xsameword_list_tl \tl_use:N \l__maieul_xsame...

\beamer@doifinframe ...té d'aire est appelée le} \keepword {\og \textit {...

When the babel package is not loaded, there are no more errors.

  1. What is the problem?
  2. And how to solve it ?
\documentclass[aspectratio=1610]{beamer}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath, amsfonts, amssymb}
\usefonttheme[onlymath]{serif}

% from egreg's answer at %https://tex.stackexchange.com/a/280981/97512 \usepackage{xparse}

\ExplSyntaxOn \NewDocumentCommand{\xsameword}{m} { \leavevmode\maieul_xsameword:n { #1 } }

\tl_new:N \l__maieul_xsameword_list_tl

\cs_new_protected:Nn \maieul_xsameword:n { \tl_set:Nn \l__maieul_xsameword_list_tl { __maieul_xsameword_start:n { #1 } } \regex_replace_all:nnN { (\c{footnote}\cB..*?\cE.) } { \cE} \1 \c{__maieul_xsameword_start:n} \cB{ } \l__maieul_xsameword_list_tl \tl_use:N \l__maieul_xsameword_list_tl } \cs_new_protected:Nn __maieul_xsameword_start:n { \tl_set:Nn \l__maieul_xsameword_list_tl { #1 } \regex_replace_all:nnN { ([^\s,.!?]+) }% Delete what should not be printed again here { \c{maieul_xsameword_format:n} \cB{ \1 \cE} } \l__maieul_xsameword_list_tl \tl_use:N \l__maieul_xsameword_list_tl }

\NewDocumentCommand{\setxsamewordformat}{m} { \cs_set_protected:Nn \maieul_xsameword_format:n { #1 } } \ExplSyntaxOff %%%%%%%%%%%%%%%%%%%%%

\newbox\mytmpbox

\newcommand{\repword}[1]{% \sbox{\mytmpbox}{#1}% \hbox to \wd\mytmpbox{\hss\hspace{.2em}''\hss}% }

\setxsamewordformat{\repword{#1}}

\newcommand{\keepword}[2]{% \sbox{\mytmpbox}{#2}% \hbox to \wd\mytmpbox{\hss#1\hss}% }

\begin{document} \begin{frame}

Lorsque le \og \textit{carreau carré} \fg{} mesure: \begin{itemize} \item {1},$cm$ de côté, l'unité d'aire est appelée le \og \textit{\textrm{centimètre carré}} \fg{} et est noté $cm^2$;

\item 1,\keepword{$dm$}{$cm$} \xsameword{de côté, l'unité d'aire est appelée le} \keepword{\og \textit{\textrm{décimètre carré}} \fg{}}{\og \textit{\textrm{centimètre carré}} \fg{}} \xsameword{et est noté} $cm^2$;

\item 1,\keepword{$m$}{$cm$} \xsameword{de côté, l'unité d'aire est appelée le} \keepword{\og \textit{\textrm{mètre carré}} \fg{}}{\og \textit{\textrm{centimètre carré}} \fg{}} \xsameword{et est noté} \keepword{$m^2$}{$cm^2$}; \end{itemize}

\end{frame} \end{document}

AndréC
  • 24,137

1 Answers1

11

It is a bug. I reported it yesterday and it has been fixed in the sources.

https://github.com/latex3/latex3/issues/909

Ulrike Fischer
  • 327,261