0

Following a previous question regarding caption modification in a long document (with a nice solution proposed by @egreg), I ended up using the changes package to handle corrections. As my document is in french, I also use the babel package with french option.

Using [french]{babel}, [final]{changes} and the caption redefinition leads to a compilation error

Removing either {babel}, [final] or the caption modification shows no error.

Can anybody clarify the issue ?

% arara: pdflatex
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage[dvipsnames,svgnames]{xcolor}
\usepackage[french]{babel}
\usepackage[justification=centering]{caption}
\usepackage{hyperref}
\usepackage[final]{changes}

% Retouche automatique de la liste des figures
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\bamboocaption}{som}
{
    \IfBooleanTF{#1}
    {
        \captioncaption*{#3}
    }
    {
        \IfValueTF{#2}
        {
            \captioncaption[#2]{#3}
        }
        {
            \seq_set_split:Nnn \l_tmpa_seq { . } { #3 }
            \int_compare:nTF { \seq_count:N \l_tmpa_seq < 2 }
            {% no period
                \captioncaption{#3}
            }
            {
                \captioncaption[\seq_item:Nn \l_tmpa_seq { 1 }]{#3}
            }
        }
    }
}
\ExplSyntaxOff

\AtBeginDocument{%
    \let\captioncaption\caption
    \let\caption\bamboocaption
}


\begin{document}

\lipsum[1]
\begin{figure}
\includegraphics[scale=0.5]{example-image-a}
\caption{Graph A. Some additional information. \label{figa}}
\end{figure}
\begin{figure}
\includegraphics[scale=0.5]{example-image-b}
\caption{Graph B. Some additional information. \label{figb}}
\end{figure}
\added{Discussion about figure~\ref{figa}}

\listoffigures

\end{document}

EDIT Log file error

! Undefined control sequence.
\r@figa ->{1}{1}{\seq 
                      _item:Nn \l _tmpa_seq {1}}{figure.caption.1}{}
l.57 \added{Discussion about figure~\ref{figa}}

EDIT File list

 *File List*
 article.cls    2018/09/03 v1.4i Standard LaTeX document class
  size10.clo    2018/09/03 v1.4i Standard LaTeX file (size option)
inputenc.sty    2018/08/11 v1.3c Input encoding file
 fontenc.sty
   t1enc.def    2018/08/11 v2.0j Standard LaTeX file
  lipsum.sty    2019/01/02 v2.2 150 paragraphs of Lorem Ipsum dummy text
   expl3.sty    2019-08-14 L3 programming layer (loader)
expl3-code.tex    2019-08-14 L3 programming layer
l3backend-pdfmode.def    2019-04-06 v L3 Experimental backend support: PDF mode

  xparse.sty    2019-05-28 L3 Experimental document command parser
  lipsum.ltd
  xcolor.sty    2016/05/11 v2.12 LaTeX color extensions (UK)
   color.cfg    2016/01/02 v1.6 sample color configuration
  pdftex.def    2018/01/08 v1.0l Graphics/color driver for pdftex
dvipsnam.def    2016/06/17 v3.0m Driver-dependent file (DPC,SPQR)
  svgnam.def    2016/05/11 v2.12 Predefined colors according to SVG 1.1 (UK)
graphicx.sty    2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR)
  keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
graphics.sty    2017/06/25 v1.2c Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    2016/01/03 v1.10 sin cos tan (DPC)
graphics.cfg    2016/06/04 v1.11 sample graphics configuration
   babel.sty    2019/07/19 3.33 The Babel package
 bblopts.cfg    2005/09/08 v0.1 add Arabic and Farsi to "declared" options of b
abel
  french.ldf    2019/03/30 v3.5e French support from the babel system
scalefnt.sty
 caption.sty    2018/10/06 v3.3-154 Customizing captions (AR)
caption3.sty    2018/09/12 v1.8c caption3 kernel (AR)
hyperref.sty    2019/06/12 v6.88h Hypertext links for LaTeX
hobsub-hyperref.sty    2016/05/16 v1.14 Bundle oberdiek, subset hyperref (HO)
hobsub-generic.sty    2016/05/16 v1.14 Bundle oberdiek, subset generic (HO)
  hobsub.sty    2016/05/16 v1.14 Construct package bundles (HO)
infwarerr.sty    2016/05/16 v1.4 Providing info/warning/error messages (HO)
 ltxcmds.sty    2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
ifluatex.sty    2016/05/16 v1.4 Provides the ifluatex switch (HO)
  ifvtex.sty    2016/05/16 v1.6 Detect VTeX and its facilities (HO)
 intcalc.sty    2016/05/16 v1.2 Expandable calculations with integers (HO)
   ifpdf.sty    2018/09/07 v3.3 Provides the ifpdf switch
etexcmds.sty    2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)
kvsetkeys.sty    2016/05/16 v1.17 Key value parser (HO)
kvdefinekeys.sty    2016/05/16 v1.4 Define keys (HO)
pdftexcmds.sty    2019/07/25 v0.30 Utility functions of pdfTeX for LuaTeX (HO)
pdfescape.sty    2016/05/16 v1.14 Implements pdfTeX's escape features (HO)
bigintcalc.sty    2016/05/16 v1.4 Expandable calculations on big integers (HO)
  bitset.sty    2016/05/16 v1.2 Handle bit-vector datatype (HO)
uniquecounter.sty    2016/05/16 v1.3 Provide unlimited unique counter (HO)
letltxmacro.sty    2016/05/16 v1.5 Let assignment for LaTeX macros (HO)
 hopatch.sty    2016/05/16 v1.3 Wrapper for package hooks (HO)
xcolor-patch.sty    2016/05/16 xcolor patch
atveryend.sty    2016/05/16 v1.9 Hooks at the very end of document (HO)
atbegshi.sty    2016/06/09 v1.18 At begin shipout hook (HO)
refcount.sty    2016/05/16 v3.5 Data extraction from label references (HO)
 hycolor.sty    2016/05/16 v1.8 Color options for hyperref/bookmark (HO)
 ifxetex.sty    2010/09/12 v0.6 Provides ifxetex conditional
 auxhook.sty    2016/05/16 v1.4 Hooks for auxiliary files (HO)
kvoptions.sty    2016/05/16 v3.12 Key value format for package options (HO)
  pd1enc.def    2019/06/12 v6.88h Hyperref: PDFDocEncoding definition (HO)
hyperref.cfg    2002/06/06 v1.2 hyperref configuration of TeXLive
     url.sty    2013/09/16  ver 3.4  Verb mode for urls, etc.
 hpdftex.def    2019/06/12 v6.88h Hyperref driver for pdfTeX
rerunfilecheck.sty    2016/05/16 v1.8 Rerun checks for auxiliary files (HO)
 changes.sty    2019/07/21 v3.1.3 changes package
 xkeyval.sty    2014/12/03 v2.7a package option processing (HA)
 xkeyval.tex    2014/12/03 v2.7a key=value parser (HA)
 xifthen.sty    2015/11/05 v1.4.0 Extended ifthen features
    calc.sty    2017/05/25 v4.3 Infix arithmetic (KKT,FJ)
  ifthen.sty    2014/09/29 v1.1c Standard LaTeX ifthen package (DPC)
 ifmtarg.sty    2018/04/16 v1.2b check for an empty argument
 xstring.sty    2019/02/06 v1.83 String manipulations (CT)
pdfcolmk.sty    2016/05/16 v1.3 Color support for pdfTeX via marks (HO)
    ulem.sty    2012/05/18
todonotes.sty    2018/11/22
    tikz.sty    2019/08/03 v3.1.4b (3.1.4b)
     pgf.sty    2019/08/03 v3.1.4b (3.1.4b)
  pgfrcs.sty    2019/08/03 v3.1.4b (3.1.4b)
everyshi.sty    2001/05/15 v3.00 EveryShipout Package (MS)
  pgfrcs.code.tex
 pgfcore.sty    2019/08/03 v3.1.4b (3.1.4b)
  pgfsys.sty    2019/08/03 v3.1.4b (3.1.4b)
  pgfsys.code.tex
pgfsyssoftpath.code.tex    2019/08/03 v3.1.4b (3.1.4b)
pgfsysprotocol.code.tex    2019/08/03 v3.1.4b (3.1.4b)
 pgfcore.code.tex
pgfcomp-version-0-65.sty    2019/08/03 v3.1.4b (3.1.4b)
pgfcomp-version-1-18.sty    2019/08/03 v3.1.4b (3.1.4b)
  pgffor.sty    2019/08/03 v3.1.4b (3.1.4b)
 pgfkeys.sty
 pgfkeys.code.tex
 pgfmath.sty
 pgfmath.code.tex
  pgffor.code.tex
    tikz.code.tex
truncate.sty    2001/08/20  ver 3.6
supp-pdf.mkii
epstopdf-base.sty    2016/05/15 v2.6 Base part for package epstopdf
  grfext.sty    2016/05/16 v1.2 Manage graphics extensions (HO)
 nameref.sty    2016/05/21 v2.44 Cross-referencing by name of section
gettitlestring.sty    2016/05/16 v1.5 Cleanup title references (HO)
    test.out
    test.out
example-image-a.pdf    Graphic file (type pdf)
example-image-b.pdf    Graphic file (type pdf)
  • On my system, when I add \usepackage{graphicx} at the start, the code runs without error (and produces the desired effect with the additional information stripped from the List of Figures). Which error message do you get exactly? – Marijn Aug 21 '19 at 19:45
  • @Marijn I added the errror in my question. It seems that the \caption modification is treated as a string and not evaluated... Or maybe I am totally mistaken. If I ignore the error, the document seems ok, but I'd prefer not leave it this way. I also added the graphicx package and the same error shows up – BambOo Aug 22 '19 at 7:31
  • It is a string (see the .aux file at the \newlabel statements) but that should not be a problem. Maybe and old version of something, could you post the *File List* that you get by putting \listfiles below \documentclass{article}? This list is visible in the terminal and in the log file, near the end. – Marijn Aug 22 '19 at 11:35
  • @Marijn I added the file list, all my packages are up-to-date according to miktex – BambOo Aug 22 '19 at 12:19
2

You want to use the expansion of \seq_item:Nn:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage[dvipsnames,svgnames]{xcolor}
\usepackage[french]{babel}
\usepackage[justification=centering]{caption}
\usepackage[final]{changes}
\usepackage{xparse}
\usepackage{hyperref}

% Retouche automatique de la liste des figures

\ExplSyntaxOn
\NewDocumentCommand{\bamboocaption}{som}
 {
  \IfBooleanTF{#1}
   {
    \captioncaption*{#3}
   }
   {
    \IfValueTF{#2}
     {
      \captioncaption[#2]{#3}
     }
     {
      \seq_set_split:Nnn \l_tmpa_seq { . } { #3 }
      \int_compare:nTF { \seq_count:N \l_tmpa_seq < 2 }
       {% no period
        \captioncaption{#3}
       }
       {
        \use:x{\exp_not:N \captioncaption[\seq_item:Nn \l_tmpa_seq { 1 }]\exp_not:n{{#3}}}
       }
     }
   }
 }
\ExplSyntaxOff

\AtBeginDocument{%
  \let\captioncaption\caption
  \let\caption\bamboocaption
}


\begin{document}

\lipsum[1]
\begin{figure}
\includegraphics[scale=0.5]{example-image-a}
\caption{Graph A. Some additional information. \label{figa}}
\end{figure}
\begin{figure}
\includegraphics[scale=0.5]{example-image-b}
\caption{Graph B. Some additional information. \label{figb}}
\end{figure}
\added{Discussion about figure~\ref{figa}}

\listoffigures

\end{document}
|improve this answer|||||
  • 1
    Thanks. Just to be sure, can you explain when the caption modification is made ? I had the impression that with the previous solution, the modification was treated as a string in the first pass, then evaluated during the second run. I don't think I understand the process. – BambOo Aug 24 '19 at 15:05
  • Your solution works on the MWE, however, when I apply it to my original document, I still have (different errors). In the .lof file, for captions containing \added \replaced or \deleted calls, I may get \contentsline {figure}{\numberline {IV.9}{\ignorespaces \added [id=N}}{107}{figure.caption.135}... I think I will remove all of these calls from the captions. – BambOo Aug 26 '19 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.