2

On the question, How to have a dynamic \cft numwidth, i.e., accordingly to the number size?, I got an answer to automatically calculate the width of my List of Listings number, so the next figure does not happens while the number grow:

enter image description here

It is working fine except on my main document because I use \usepackage{hyphenat}\useshorthands{~}\defineshorthand{~=}{\hyp{}}, which makes the ~ an active character and when the code which computes the width of the list of listings numbers run, it throws the error: Argument of \user@active@arg~ has an extra }. (reference).

I tried putting \shorthandoff{~} and \shorthandoff{~} around the commands which calculate the width, but it does not worked the the error persists:

How can I disable the shorthand only when width of the list of listings number are being computed/calculated?

\PassOptionsToPackage{french}{babel}
\documentclass[english,12pt,a4paper,twoside]{abntex2}
\usepackage[T1]{fontenc}
\usepackage{caption,listings}

\usepackage{hyphenat}
\useshorthands{~}\defineshorthand{~=}{\hyp{}} % <--- Here breaks everything

\makeatletter
% get rid of the one listings may have provided
\let\lstlistoflistings\relax

% whatever this does, it seems to work
\begingroup
\let\newcounter\@gobble\let\setcounter\@gobbletwo
\globaldefs\@ne \let\c@loldepth\@ne
\newlistof{listings}{lol}{\lstlistlistingname}
\newlistof{lstlistoflistings}{lol}{\lstlistlistingname}
\newlistentry{lstlisting}{lol}{0}
\endgroup

\newlength\widestlistings

% use the hook in numberline to gather the width of the widest number
\renewcommand*\numberlinehook[1]{%
  \shorthandoff{~}
  \expandafter\nametest\expandafter{\cftwhatismyname}{lstlisting}%
  \ifsamename%
    \settowidth\@tempdimc{\@nameuse{cft\cftwhatismyname font}#1}%
    \ifdim\@tempdimc>\widestlistings\relax
       \global\widestlistings=\@tempdimc
    \fi
  \fi
  \shorthandon{~}
}

% widest number in the aux to be used on the next pass
\renewcommand\cftlolafterlisthook{
  \shorthandoff{~}
  \typeout{w: \the\widestlistings}
  \immediate\write\@mainaux{\string\gdef\string\savedlolwidth{\the\widestlistings}}
  \shorthandon{~}
}

% prefix listing entries
\renewcommand\cftlstlistingname{\lstlistingname~}%

% autoadjust the width of the numwidth box, delayed so we can access the saved number
\AtBeginDocument{
  \setlength\cftlstlistingnumwidth{%
    \dimexpr\@ifundefined{savedlolwidth}{1em}{\@nameuse{savedlolwidth}}
    +2em
  }%
}
\renewcommand\cftlstlistingaftersnum{\hfill\textendash\hfill}%


\makeatother

\begin{document}


\lstlistoflistings*

Source~=code shorthand.

% \newpage

\begin{lstlisting}[caption={Listing A}]
# If the body of the namespace is longer than this
# number, it won't be indented. Requires
\end{lstlisting}
% \newpage

\setcounter{lstlisting}{1000}


\begin{lstlisting}[caption={Listing B}]
# If the body of the namespace is longer than this
# number, it won't be indented. Requires
\end{lstlisting}
% \newpage

\end{document}

Update

I also tried to delay the usage of the macro as suggested on Why \shorthandon and \shorthandoff cannot be embedded in other macros?, but it does not worked.

% use the hook in numberline to gather the width of the widest number
\renewcommand*\numberlinehook{%
  \shorthandoff{~}
  \numberlinehookshorthandoff
}

\newcommand{\numberlinehookshorthandoff}[1]{
  \expandafter\nametest\expandafter{\cftwhatismyname}{lstlisting}%
  \ifsamename%
    \settowidth\@tempdimc{\@nameuse{cft\cftwhatismyname font}#1}%
    \ifdim\@tempdimc>\widestlistings\relax
       \global\widestlistings=\@tempdimc
    \fi
  \fi
}

\renewcommand\cftlolafterlisthook{
  \shorthandoff{~}
  \cftlolafterlisthookshorthandoff
}

% widest number in the aux to be used on the next pass
\newcommand{\cftlolafterlisthookshorthandoff}{
  \typeout{w: \the\widestlistings}
  \immediate\write\@mainaux{\string\gdef\string\savedlolwidth{\the\widestlistings}}
  \shorthandon{~}
}

2 Answers 2

1

The error here doesn't pop up when the widths of the entries in the list of listings are calculated, but whenever an ~ is used in the code to typeset a non-breakable space. In your example this occurs at two locations:

  1. When the Listing X entries are printed in the list of listings.
  2. When the Listing X caption is printed for each individual listing.

What we need to do to fix these problems is to keep the original meaning of ~ and restore it locally. We store the meaning before babel is loaded:

\makeatletter \let\tilde@space=~ \makeatother

The problem in the list of listings can be fixed by redefining \cftlstlistingname to use the original ~:

\renewcommand\cftlstlistingname{\lstlistingname\tilde@space}

For the individual listing captions we redefine the starting part of the lstlisting environment and restore the original ~ meaning locally:

\let\orig@lstlisting=\lstlisting
\renewcommand\lstlisting{\let~=\tilde@space \orig@lstlisting}

You perhaps shouldn't use ~= as a shorthand command, because many packages rely on the original definition of ~. Sooner or later you will likely run into more places that break.

Full updated example:

\makeatletter
\let\tilde@space=~
\makeatother

\PassOptionsToPackage{french}{babel}
\documentclass[english,12pt,a4paper,twoside]{abntex2}
\usepackage[T1]{fontenc}
\usepackage{caption,listings}

\usepackage{hyphenat}
\useshorthands{~}\defineshorthand{~=}{\hyp{}} % <--- Here breaks everything

\makeatletter
% get rid of the one listings may have provided
\let\lstlistoflistings\relax

% whatever this does, it seems to work
\begingroup
\let\newcounter\@gobble\let\setcounter\@gobbletwo
\globaldefs\@ne \let\c@loldepth\@ne
\newlistof{listings}{lol}{\lstlistlistingname}
\newlistof{lstlistoflistings}{lol}{\lstlistlistingname}
\newlistentry{lstlisting}{lol}{0}
\endgroup

\newlength\widestlistings

% use the hook in numberline to gather the width of the widest number
\renewcommand*\numberlinehook[1]{%
  \shorthandoff{~}
  \expandafter\nametest\expandafter{\cftwhatismyname}{lstlisting}%
  \ifsamename%
    \settowidth\@tempdimc{\@nameuse{cft\cftwhatismyname font}#1}%
    \ifdim\@tempdimc>\widestlistings\relax
       \global\widestlistings=\@tempdimc
    \fi
  \fi
  \shorthandon{~}
}

% widest number in the aux to be used on the next pass
\renewcommand\cftlolafterlisthook{
  \shorthandoff{~}
  \typeout{w: \the\widestlistings}
  \immediate\write\@mainaux{\string\gdef\string\savedlolwidth{\the\widestlistings}}
  \shorthandon{~}
}

% prefix listing entries
\renewcommand\cftlstlistingname{\lstlistingname~}%

% autoadjust the width of the numwidth box, delayed so we can access the saved number
\AtBeginDocument{
  \setlength\cftlstlistingnumwidth{%
    \dimexpr\@ifundefined{savedlolwidth}{1em}{\@nameuse{savedlolwidth}}
    +2em
  }%
}
\renewcommand\cftlstlistingaftersnum{\hfill\textendash\hfill}%

\renewcommand\cftlstlistingname{\lstlistingname\tilde@space}
\let\orig@lstlisting=\lstlisting
\renewcommand\lstlisting{\let~=\tilde@space \orig@lstlisting}

\makeatother

\begin{document}

\lstlistoflistings*

Source~=code shorthand.

\begin{lstlisting}[caption={Listing A}]
# If the body of the namespace is longer than this
# number, it won't be indented. Requires
\end{lstlisting}

\setcounter{lstlisting}{1000}

\begin{lstlisting}[caption={Listing B}]
# If the body of the namespace is longer than this
# number, it won't be indented. Requires
\end{lstlisting}

Source~=code shorthand.

\end{document}

enter image description here

2
  • Thanks! I was just checking babel documentation, and I must to use \shorthandoff* (star), because ~ is active and the no start version will make it inactive and it will stop working: \shorthandoff does not behave as you would expect with characters like ~ or ^, because they usually are not “other”. For them \shorthandoff* is provided, so that with \shorthandoff*{~^} ~ is still active, very likely with the meaning of a non-breaking space, and ^ is the superscript character. The catcodes used are those when the shorthands are defined,`usually when language files are loaded.
    – user
    Nov 7, 2019 at 1:28
  • Althougn, I have tested using the started version of \shorthandoff and it has been breaking the shorthand usage of ~= in my captions, while the non stared version keeps everything working fine.
    – user
    Nov 7, 2019 at 2:14
1

I also managed to make a solution which works just by appending a trailing empty {} group to the tilde ~ when it is used as the last symbol, just be before a close brace:

\renewcommand\cftlstlistingname{\lstlistingname~{}}

enter image description here

\PassOptionsToPackage{french}{babel}
\documentclass[english,12pt,a4paper,twoside]{abntex2}
\usepackage[T1]{fontenc}
\usepackage{caption,listings}

\usepackage{hyphenat}
\useshorthands{~}\defineshorthand{~=}{\hyp{}}

% get rid of the one listings may have provided
\makeatletter
\let\lstlistoflistings\relax

% whatever this does, it seems to work
\begingroup
  \let\newcounter\@gobble\let\setcounter\@gobbletwo
  \globaldefs\@ne \let\c@loldepth\@ne
  \newlistof{listings}{lol}{\lstlistlistingname}
  \newlistof{lstlistoflistings}{lol}{\lstlistlistingname}
  \newlistentry{lstlisting}{lol}{0}
\endgroup

\newlength\widestlistings

% use the hook in numberline to gather the width of the widest number
\renewcommand*\numberlinehook[1]{%
  \expandafter\nametest\expandafter{\cftwhatismyname}{lstlisting}%
  \ifsamename%
    \shorthandoff{~}
      \settowidth\@tempdimc{\@nameuse{cft\cftwhatismyname font}#1}%
    \shorthandon{~}
    \ifdim\@tempdimc>\widestlistings\relax
       \global\widestlistings=\@tempdimc
    \fi
  \fi
}

% save the widest number in the aux file to be used on the next pass
\renewcommand\cftlolafterlisthook{
  \typeout{The widest listings number is: \the\widestlistings}
  \immediate\write\@mainaux{\string\gdef\string\savedlolwidth{\the\widestlistings}}
}

% prefix listing entries
\renewcommand\cftlstlistingname{\lstlistingname~{}}

% autoadjust the width of the numwidth box, delayed so we can access the saved number
\AtBeginDocument{
  \setlength\cftlstlistingnumwidth{%
    \dimexpr\@ifundefined{savedlolwidth}{1em}{\@nameuse{savedlolwidth}}
    +2em
  }%
}
\renewcommand\cftlstlistingaftersnum{\hfill\textendash\hfill}%


\makeatother

\begin{document}

\lstlistoflistings*

Source~=code shorthand.

\begin{lstlisting}[caption={Listing~=A}]
# If the body of the namespace is longer than this
# number, it won't be indented. Requires
\end{lstlisting}

\setcounter{lstlisting}{1000}

\begin{lstlisting}[caption={Listing~=B}]
# If the body of the namespace is longer than this
# number, it won't be indented. Requires
\end{lstlisting}

Source~=code shorthand.

\end{document}

main.log

This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016/Debian) (preloaded format=pdflatex 2019.10.19)  7 NOV 2019 01:25
entering extended mode
 restricted \write18 enabled.
 %&-line parsing enabled.
**main.tex -shell-escape
(./main.tex
LaTeX2e <2017/01/01> patch level 3
Babel <3.9r> and hyphenation patterns for 83 language(s) loaded.
(/usr/share/texlive/texmf-dist/tex/latex/abntex2/abntex2.cls
Document Class: abntex2 2016/02/26 v-1.9.6 abnTeX2
(/usr/share/texlive/texmf-dist/tex/latex/base/ifthen.sty
Package: ifthen 2014/09/29 v1.1c Standard LaTeX ifthen package (DPC)
)
(/usr/share/texlive/texmf-dist/tex/latex/memoir/memoir.cls
Document Class: memoir 2016/05/16 v3.7f configurable book, report, article docu
ment class
\onelineskip=\skip41
\lxvchars=\skip42
\xlvchars=\skip43
\@memcnta=\count79
\c@@memmarkcntra=\count80
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifpdf.sty
Package: ifpdf 2016/05/14 v3.1 Provides the ifpdf switch
)
(/usr/share/texlive/texmf-dist/tex/latex/ifetex/ifetex.sty
Package: ifetex 2011/12/15 v1.2 ifetex

(/usr/share/texlive/texmf-dist/tex/plain/ifetex/ifetex.tex))
(/usr/share/texlive/texmf-dist/tex/generic/ifxetex/ifxetex.sty
Package: ifxetex 2010/09/12 v0.6 Provides ifxetex conditional
)
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifluatex.sty
Package: ifluatex 2016/05/16 v1.4 Provides the ifluatex switch (HO)
Package ifluatex Info: LuaTeX not detected.
)
\stockheight=\skip44
\stockwidth=\skip45
\trimtop=\skip46
\trimedge=\skip47

(/usr/share/texlive/texmf-dist/tex/latex/memoir/mem12.clo
File: mem12.clo 2010/10/19 v0.4b memoir class 12pt size option
)
\binding=\skip48
\spinemargin=\skip49
\foremargin=\skip50
\uppermargin=\skip51
\lowermargin=\skip52
\headdrop=\skip53
\normalrulethickness=\skip54
\mem@maxheadheight=\skip55
\mem@maxfootheight=\skip56
\headwidth=\skip57
\c@storedpagenumber=\count81
\memPD=\dimen102
\m@mabparskip=\skip58
\thanksmarkwidth=\skip59
\thanksmarksep=\skip60
\droptitle=\skip61
\c@book=\count82
\c@part=\count83
\c@chapter=\count84
\c@section=\count85
\c@subsection=\count86
\c@subsubsection=\count87
\c@paragraph=\count88
\c@subparagraph=\count89
\beforechapskip=\skip62
\midchapskip=\skip63
\afterchapskip=\skip64
\chapindent=\skip65
\bottomsectionskip=\skip66
\secindent=\skip67
\beforesecskip=\skip68
\aftersecskip=\skip69
\subsecindent=\skip70
\beforesubsecskip=\skip71
\aftersubsecskip=\skip72
\subsubsecindent=\skip73
\beforesubsubsecskip=\skip74
\aftersubsubsecskip=\skip75
\paraindent=\skip76
\beforeparaskip=\skip77
\afterparaskip=\skip78
\subparaindent=\skip79
\beforesubparaskip=\skip80
\aftersubparaskip=\skip81
\pfbreakskip=\skip82
\c@@ppsavesec=\count90
\c@@ppsaveapp=\count91
\ragrparindent=\dimen103
\everylistparindent=\dimen104
\parsepi=\skip83
\topsepi=\skip84
\itemsepi=\skip85
\parsepii=\skip86
\topsepii=\skip87
\topsepiii=\skip88
\itemsepii=\skip89
\itemsepiii=\skip90
\partopsepii=\skip91
\partopsepiii=\skip92
\m@msavetopsep=\skip93
\m@msavepartopsep=\skip94
\@enLab=\toks14
\abstitleskip=\skip95
\absleftindent=\skip96
\abs@leftindent=\dimen105
\absrightindent=\skip97
\absparindent=\skip98
\absparsep=\skip99
\c@vslineno=\count92
\c@poemline=\count93
\c@modulo@vs=\count94
\c@memfvsline=\count95
\vleftskip=\skip100
\vrightskip=\skip101
\stanzaskip=\skip102
\versewidth=\skip103
\vgap=\skip104
\vindent=\skip105
\vleftmargin=\dimen106
\c@verse=\count96
\c@chrsinstr=\count97
\beforepoemtitleskip=\skip106
\afterpoemtitleskip=\skip107
\c@poem=\count98
\beforePoemTitleskip=\skip108
\midPoemTitleskip=\skip109
\afterPoemTitleskip=\skip110
\col@sep=\dimen107
\extrarowheight=\dimen108
\NC@list=\toks15
\extratabsurround=\skip111
\backup@length=\skip112
\TX@col@width=\dimen109
\TX@old@table=\dimen110
\TX@old@col=\dimen111
\TX@target=\dimen112
\TX@delta=\dimen113
\TX@cols=\count99
\TX@ftn=\toks16
\heavyrulewidth=\dimen114
\lightrulewidth=\dimen115
\cmidrulewidth=\dimen116
\belowrulesep=\dimen117
\belowbottomsep=\dimen118
\aboverulesep=\dimen119
\abovetopsep=\dimen120
\cmidrulesep=\dimen121
\cmidrulekern=\dimen122
\defaultaddspace=\dimen123
\@cmidla=\count100
\@cmidlb=\count101
\@aboverulesep=\dimen124
\@belowrulesep=\dimen125
\@thisruleclass=\count102
\@lastruleclass=\count103
\@thisrulewidth=\dimen126
\ctableftskip=\skip113
\ctabrightskip=\skip114
\abovecolumnspenalty=\count104
\@linestogo=\count105
\@cellstogo=\count106
\@cellsincolumn=\count107
\crtok=\toks17
\@mincolumnwidth=\dimen127
\c@newflo@tctr=\count108
\mem@margin@floatbox=\box26
\@contcwidth=\skip115
\@contindw=\skip116
\abovecaptionskip=\skip117
\belowcaptionskip=\skip118
\subfloattopskip=\skip119
\subfloatcapskip=\skip120
\subfloatcaptopadj=\skip121
\subfloatbottomskip=\skip122
\subfloatlabelskip=\skip123
\subfloatcapmargin=\dimen128
\c@@contsubnum=\count109
\m@mscap@capbox=\box27
\m@mscap@fbox=\box28
\sidecapsep=\dimen129
\sidecapwidth=\dimen130
\m@m@tempdima=\dimen131
\m@mscapraise=\dimen132
\sidecapraise=\dimen133
\m@mscapmainwidth=\dimen134
\m@mscaplkern=\dimen135
\beforeepigraphskip=\skip124
\afterepigraphskip=\skip125
\epigraphwidth=\skip126
\epigraphrule=\skip127
LaTeX Info: Redefining \em on input line 7551.
LaTeX Info: Redefining \emph on input line 7559.
\tocentryskip=\skip128
\tocbaseline=\skip129
\cftparskip=\skip130
\cftbeforebookskip=\skip131
\cftbookindent=\dimen136
\cftbooknumwidth=\dimen137
\cftbeforepartskip=\skip132
\cftpartindent=\skip133
\cftpartnumwidth=\skip134
\cftbeforechapterskip=\skip135
\cftchapterindent=\skip136
\cftchapternumwidth=\skip137
\cftbeforesectionskip=\skip138
\cftsectionindent=\skip139
\cftsectionnumwidth=\skip140
\cftbeforesubsectionskip=\skip141
\cftsubsectionindent=\skip142
\cftsubsectionnumwidth=\skip143
\cftbeforesubsubsectionskip=\skip144
\cftsubsubsectionindent=\skip145
\cftsubsubsectionnumwidth=\skip146
\cftbeforeparagraphskip=\skip147
\cftparagraphindent=\skip148
\cftparagraphnumwidth=\skip149
\cftbeforesubparagraphskip=\skip150
\cftsubparagraphindent=\skip151
\cftsubparagraphnumwidth=\skip152
\prechapterprecisshift=\dimen138
\c@maxsecnumdepth=\count110
\bibindent=\dimen139
\bibitemsep=\skip153
\indexcolsep=\skip154
\indexrule=\skip155
\indexmarkstyle=\toks18
\@indexbox=\insert199
\glossarycolsep=\dimen140
\glossaryrule=\dimen141
\sideparvshift=\skip156
\sideins=\insert198
\sidebartopsep=\skip157
\sidebarhsep=\skip158
\sidebarvsep=\skip159
\sidebarwidth=\skip160
\footmarkwidth=\skip161
\footmarksep=\skip162
\footparindent=\skip163
\footinsdim=\skip164
\footinsv@r=\insert197
\@mpfootinsv@r=\insert196
\m@m@k=\count111
\m@m@h=\dimen142
\m@mipn@skip=\skip165
\sidefootins=\insert195
\sidefootadjust=\skip166
\sidefootheight=\skip167
\sidefoothsep=\skip168
\sidefootvsep=\skip169
\sidefootwidth=\skip170
\m@mdownsf=\skip171
\c@sidefootnote=\count112
\sidefootmarkwidth=\skip172
\sidefootmarksep=\skip173
\sidefootparindent=\skip174
\c@pagenote=\count113
\c@pagenoteshadow=\count114
\mem@pn@lastkern=\skip175
\every@verbatim=\toks19
\afterevery@verbatim=\toks20
\verbatim@line=\toks21
\tab@position=\count115
\verbatim@in@stream=\read1
\verbatimindent=\skip176
\verbatim@out=\write3
\bvboxsep=\skip177
\c@memfbvline=\count116
\c@bvlinectr=\count117
\bvnumlength=\skip178
\fb@frw=\dimen143
\fb@frh=\dimen144
\FrameRule=\dimen145
\FrameSep=\dimen146
\c@cp@cntr=\count118
LaTeX Info: Redefining \: on input line 12068.
LaTeX Info: Redefining \! on input line 12070.
\c@ism@mctr=\count119
\c@xsm@mctr=\count120
\c@csm@mctr=\count121
\c@ksm@mctr=\count122
\c@xksm@mctr=\count123
\c@cksm@mctr=\count124
\c@msm@mctr=\count125
\c@xmsm@mctr=\count126
\c@cmsm@mctr=\count127
\c@bsm@mctr=\count128
\c@workm@mctr=\count129
\c@sheetsequence=\count130
\c@lastsheet=\count131
\c@lastpage=\count132
\c@figure=\count133
\c@lofdepth=\count134
\cftbeforefigureskip=\skip179
\cftfigureindent=\skip180
\cftfigurenumwidth=\skip181
\c@table=\count135
\c@lotdepth=\count136
\cftbeforetableskip=\skip182
\cfttableindent=\skip183
\cfttablenumwidth=\skip184
Package abstract [2008/07/23] emulated by memoir.
Package appendix [2008/07/23] emulated by memoir.
Package array [2008/09/09] emulated by memoir.
Package booktabs [2016/05/16] emulated by memoir.
Package ccaption [2008/07/23] emulated by memoir.
Package changepage [2008/07/23] emulated by memoir.
Package chngcntr [2008/07/23] emulated by memoir.
Package chngpage [2008/07/23] emulated by memoir.
Package crop emulated by memoir.
Package dcolumn [2008/07/23] emulated by memoir.
Package delarray [2008/07/23] emulated by memoir.
Package enumerate [2008/07/23] emulated by memoir.
Package epigraph [2008/07/23] emulated by memoir.
Package ifmtarg [2008/07/23] emulated by memoir.
Package index [2008/07/23] emulated by memoir.
Package makeidx [2008/07/23] emulated by memoir.
Package moreverb [2008/07/23] emulated by memoir.
Package mparhack [2008/07/23] emulated by memoir.
Package needspace [2008/07/23] emulated by memoir.
Package newfile [2008/07/23] emulated by memoir.
Package nextpage [2008/07/23] emulated by memoir.
Package pagenote [2008/07/23] emulated by memoir.
Package parskip [2008/07/23] emulated by memoir.
Package patchcmd [2008/07/23] emulated by memoir.
Package setspace [2008/07/23] emulated by memoir.
Package shortvrb [2008/07/23] emulated by memoir.
Package showidx [2008/07/23] emulated by memoir.
Package tabularx [2008/07/23] emulated by memoir.
Package titleref [2008/07/23] emulated by memoir.
Package titling [2008/07/23] emulated by memoir.
Package tocbibind [2008/07/23] emulated by memoir.
Package tocloft [2008/07/23] emulated by memoir.
Package tocvsec2 [2008/07/23] emulated by memoir.
Package verbatim [2008/07/23] emulated by memoir.
Package verse [2008/07/23] emulated by memoir.

(/usr/share/texlive/texmf-dist/tex/latex/memoir/mempatch.sty
Package: mempatch 2009/07/24 v6.0f Patches for memoir class v1.6180339
))
(/usr/share/texlive/texmf-dist/tex/latex/textcase/textcase.sty
Package: textcase 2004/10/07 v0.07 Text only upper/lower case changing (DPC)
LaTeX Info: Redefining \MakeTextUppercase on input line 47.
LaTeX Info: Redefining \MakeTextLowercase on input line 50.
)
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref.sty
Package: hyperref 2016/06/24 v6.83q Hypertext links for LaTeX

(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/hobsub-hyperref.sty
Package: hobsub-hyperref 2016/05/16 v1.14 Bundle oberdiek, subset hyperref (HO)


(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/hobsub-generic.sty
Package: hobsub-generic 2016/05/16 v1.14 Bundle oberdiek, subset generic (HO)
Package: hobsub 2016/05/16 v1.14 Construct package bundles (HO)
Package: infwarerr 2016/05/16 v1.4 Providing info/warning/error messages (HO)
Package: ltxcmds 2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
Package hobsub Info: Skipping package `ifluatex' (already loaded).
Package: ifvtex 2016/05/16 v1.6 Detect VTeX and its facilities (HO)
Package ifvtex Info: VTeX not detected.
Package: intcalc 2016/05/16 v1.2 Expandable calculations with integers (HO)
Package hobsub Info: Skipping package `ifpdf' (already loaded).
Package: etexcmds 2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)
Package etexcmds Info: Could not find \expanded.
(etexcmds)             That can mean that you are not using pdfTeX 1.50 or
(etexcmds)             that some package has redefined \expanded.
(etexcmds)             In the latter case, load this package earlier.
Package: kvsetkeys 2016/05/16 v1.17 Key value parser (HO)
Package: kvdefinekeys 2016/05/16 v1.4 Define keys (HO)
Package: pdftexcmds 2016/05/21 v0.22 Utility functions of pdfTeX for LuaTeX (HO
)
Package pdftexcmds Info: LuaTeX not detected.
Package pdftexcmds Info: \pdf@primitive is available.
Package pdftexcmds Info: \pdf@ifprimitive is available.
Package pdftexcmds Info: \pdfdraftmode found.
Package: pdfescape 2016/05/16 v1.14 Implements pdfTeX's escape features (HO)
Package: bigintcalc 2016/05/16 v1.4 Expandable calculations on big integers (HO
)
Package: bitset 2016/05/16 v1.2 Handle bit-vector datatype (HO)
Package: uniquecounter 2016/05/16 v1.3 Provide unlimited unique counter (HO)
)
Package hobsub Info: Skipping package `hobsub' (already loaded).
Package: letltxmacro 2016/05/16 v1.5 Let assignment for LaTeX macros (HO)
Package: hopatch 2016/05/16 v1.3 Wrapper for package hooks (HO)
Package: xcolor-patch 2016/05/16 xcolor patch
Package: atveryend 2016/05/16 v1.9 Hooks at the very end of document (HO)
Package atveryend Info: \enddocument detected (standard20110627).
Package: atbegshi 2016/06/09 v1.18 At begin shipout hook (HO)
Package: refcount 2016/05/16 v3.5 Data extraction from label references (HO)
Package: hycolor 2016/05/16 v1.8 Color options for hyperref/bookmark (HO)
)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty
Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
\KV@toks@=\toks22
)
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/auxhook.sty
Package: auxhook 2016/05/16 v1.4 Hooks for auxiliary files (HO)
)
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/kvoptions.sty
Package: kvoptions 2016/05/16 v3.12 Key value format for package options (HO)
)
\@linkdim=\dimen147
\Hy@linkcounter=\count137
\Hy@pagecounter=\count138

(/usr/share/texlive/texmf-dist/tex/latex/hyperref/pd1enc.def
File: pd1enc.def 2016/06/24 v6.83q Hyperref: PDFDocEncoding definition (HO)
)
\Hy@SavedSpaceFactor=\count139

(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/hyperref.cfg
File: hyperref.cfg 2002/06/06 v1.2 hyperref configuration of TeXLive
)
Package hyperref Info: Hyper figures OFF on input line 4486.
Package hyperref Info: Link nesting OFF on input line 4491.
Package hyperref Info: Hyper index ON on input line 4494.
Package hyperref Info: Plain pages OFF on input line 4501.
Package hyperref Info: Backreferencing OFF on input line 4506.
Package hyperref Info: Implicit mode ON; LaTeX internals redefined.
Package hyperref Info: Bookmarks ON on input line 4735.
\c@Hy@tempcnt=\count140

(/usr/share/texlive/texmf-dist/tex/latex/url/url.sty
\Urlmuskip=\muskip10
Package: url 2013/09/16  ver 3.4  Verb mode for urls, etc.
)
LaTeX Info: Redefining \url on input line 5088.
\XeTeXLinkMargin=\dimen148
\Fld@menulength=\count141
\Field@Width=\dimen149
\Fld@charsize=\dimen150
Package hyperref Info: Hyper figures OFF on input line 6342.
Package hyperref Info: Link nesting OFF on input line 6347.
Package hyperref Info: Hyper index ON on input line 6350.
Package hyperref Info: backreferencing OFF on input line 6357.
Package hyperref Info: Link coloring OFF on input line 6362.
Package hyperref Info: Link coloring with OCG OFF on input line 6367.
Package hyperref Info: PDF/A mode OFF on input line 6372.
LaTeX Info: Redefining \ref on input line 6412.
LaTeX Info: Redefining \pageref on input line 6416.
\Hy@abspage=\count142
\c@Item=\count143
\c@Hfootnote=\count144
)
(/usr/share/texlive/texmf-dist/tex/latex/memoir/memhfixc.sty
Package: memhfixc 2013/05/30 v1.17 nameref/hyperref package fixes for memoir cl
ass
\c@memhycontfloat=\count145
\c@Hpagenote=\count146
)

Package hyperref Message: Driver (autodetected): hpdftex.

(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hpdftex.def
File: hpdftex.def 2016/06/24 v6.83q Hyperref driver for pdfTeX
\Fld@listcount=\count147
\c@bookmark@seq@number=\count148

(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty
Package: rerunfilecheck 2016/05/16 v1.8 Rerun checks for auxiliary files (HO)
Package uniquecounter Info: New unique counter `rerunfilecheck' on input line 2
82.
)
\Hy@SectionHShift=\skip185
)
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/bookmark.sty
Package: bookmark 2016/05/17 v1.26 PDF bookmarks (HO)

(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/bkm-pdftex.def
File: bkm-pdftex.def 2016/05/17 v1.26 bookmark driver for pdfTeX (HO)
\BKM@id=\count149
))
(/usr/share/texlive/texmf-dist/tex/generic/babel/babel.sty
Package: babel 2016/04/23 3.9r The Babel package

(/usr/share/texlive/texmf-dist/tex/generic/babel-english/english.ldf
Language: english 2012/08/20 v3.3p English support from the babel system

(/usr/share/texlive/texmf-dist/tex/generic/babel/babel.def
File: babel.def 2016/04/23 3.9r Babel common definitions
\babel@savecnt=\count150
\U@D=\dimen151
)
\l@canadian = a dialect from \language\l@american 
\l@australian = a dialect from \language\l@british 
\l@newzealand = a dialect from \language\l@british 
)
(/usr/share/texlive/texmf-dist/tex/generic/babel-french/frenchb.ldf
Language: frenchb 2017/01/15 v3.2f French support from the babel system
\l@acadian = a dialect from \language\l@french 
\l@canadien = a dialect from \language\l@french 
\FB@nonchar=\count151
\FBcolonskip=\skip186
\FBthinskip=\skip187
Package babel Info: Making : an active character on input line 365.
Package babel Info: Making ; an active character on input line 366.
Package babel Info: Making ! an active character on input line 367.
Package babel Info: Making ? an active character on input line 368.
\FBguillskip=\skip188
\FBguill@level=\count152
\FB@everypar=\toks23
\FB@Mht=\dimen152
\mc@charclass=\count153
\mc@charfam=\count154
\mc@charslot=\count155
\std@mcc=\count156
\dec@mcc=\count157
\listindentFB=\skip189
\descindentFB=\skip190
\labelwidthFB=\skip191
\leftmarginFB=\skip192
\parindentFFN=\dimen153
\FBfnindent=\skip193
)
(/usr/share/texlive/texmf-dist/tex/generic/babel-portuges/portuges.ldf
Language: portuges 2008/03/18 v1.2q Portuguese support from the babel system
\l@brazil = a dialect from \language\l@portuges 
Package babel Info: Making " an active character on input line 145.
))
(/usr/share/texlive/texmf-dist/tex/latex/carlisle/scalefnt.sty)
(/usr/share/texlive/texmf-dist/tex/latex/enumitem/enumitem.sty
Package: enumitem 2011/09/28 v3.5.2 Customized lists
\labelindent=\skip194
\enit@outerparindent=\dimen154
\enit@toks=\toks24
\enit@inbox=\box29
\enitdp@description=\count158
)
(/usr/share/texlive/texmf-dist/tex/latex/tools/calc.sty
Package: calc 2014/10/28 v4.3 Infix arithmetic (KKT,FJ)
\calc@Acount=\count159
\calc@Bcount=\count160
\calc@Adimen=\dimen155
\calc@Bdimen=\dimen156
\calc@Askip=\skip256
\calc@Bskip=\skip257
LaTeX Info: Redefining \setlength on input line 80.
LaTeX Info: Redefining \addtolength on input line 81.
\calc@Ccount=\count161
\calc@Cskip=\skip258
)

******************************************************
Stock height and width: 845.04684pt by 597.50787pt
Top and edge trims: 0pt and 0pt
Page height and width: 845.04684pt by 597.50787pt
Text height and width: 708pt by 455pt
Spine and edge margins: 85.35826pt and 56.9055pt
Upper and lower margins: 85.35826pt and 51.68858pt
Headheight and headsep: 14.5pt and 19.8738pt
Footskip: 30pt
Columnsep and columnseprule: 10pt and 0pt
Marginparsep and marginparwidth: 7pt and 42.9055pt
Sidecapsep and sidecapwidth: 7pt and 92pt
Sidebarhsep and sidebarwidth: 7pt and 92pt
Sidebarvsep and sidebartopsep: 14.5pt and 0pt
Sidebarheight: 590.14995pt
Sidefoothsep and sidefootwidth: 7pt and 92pt
Sidefootvsep and sidefootheight: 14.5pt and 590.14995pt
******************************************************

\c@abntex@bookmarkcounter=\count162
\cftlastnumwidth=\skip259
\chapternamenumlength=\skip260
\ABNTEXcitacaorecuo=\skip261
\c@alineasi=\count163
\c@alineasii=\count164
\enitdp@alineas=\count165
\c@subalineasi=\count166
\enitdp@subalineas=\count167
\c@incisosi=\count168
\enitdp@incisos=\count169
\ABNTEXsignwidth=\skip262
\ABNTEXsignthickness=\skip263
\ABNTEXsignskip=\skip264
) (/usr/share/texlive/texmf-dist/tex/latex/base/fontenc.sty
Package: fontenc 2017/02/22 v2.0g Standard LaTeX package

(/usr/share/texlive/texmf-dist/tex/latex/base/t1enc.def
File: t1enc.def 2017/02/22 v2.0g Standard LaTeX file
LaTeX Font Info:    Redeclaring font encoding T1 on input line 48.
))

Class memoir Warning: You are using the caption package with the memoir class. 
To prepare we will now reset all captioning macros and configurations to kernel
 defaults, and then let the caption package take over. Please remember to use
 the caption package interfaces in order to
 configure your captions.

(/usr/share/texlive/texmf-dist/tex/latex/caption/caption.sty
Package: caption 2016/02/21 v3.3-144 Customizing captions (AR)

(/usr/share/texlive/texmf-dist/tex/latex/caption/caption3.sty
Package: caption3 2016/05/22 v1.7-166 caption3 kernel (AR)
Package caption3 Info: TeX engine: e-TeX on input line 67.
\captionmargin=\dimen157
\captionmargin@=\dimen158
\captionwidth=\dimen159
\caption@tempdima=\dimen160
\caption@indent=\dimen161
\caption@parindent=\dimen162
\caption@hangindent=\dimen163
)
\c@ContinuedFloat=\count170
Package caption Info: hyperref package is loaded.
)
(/usr/share/texlive/texmf-dist/tex/latex/listings/listings.sty
\lst@mode=\count171
\lst@gtempboxa=\box30
\lst@token=\toks25
\lst@length=\count172
\lst@currlwidth=\dimen164
\lst@column=\count173
\lst@pos=\count174
\lst@lostspace=\dimen165
\lst@width=\dimen166
\lst@newlines=\count175
\lst@lineno=\count176
\lst@maxwidth=\dimen167

(/usr/share/texlive/texmf-dist/tex/latex/listings/lstmisc.sty
File: lstmisc.sty 2015/06/04 1.6 (Carsten Heinz)
\c@lstnumber=\count177
\lst@skipnumbers=\count178
\lst@framebox=\box31
)
(/usr/share/texlive/texmf-dist/tex/latex/listings/listings.cfg
File: listings.cfg 2015/06/04 1.6 listings configuration
))
Package: listings 2015/06/04 1.6 (Carsten Heinz)

(/usr/share/texlive/texmf-dist/tex/latex/hyphenat/hyphenat.sty
Package: hyphenat 2009/09/02 v2.3c hyphenation utilities
\langwohyphens=\language83
LaTeX Info: Redefining \_ on input line 43.
)
\cftbeforelstlistingskip=\skip265
\cftlstlistingindent=\skip266
\cftlstlistingnumwidth=\skip267
\widestlistings=\skip268
 (./main.aux)
\openout1 = `main.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 58.
LaTeX Font Info:    ... okay on input line 58.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 58.
LaTeX Font Info:    ... okay on input line 58.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 58.
LaTeX Font Info:    ... okay on input line 58.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 58.
LaTeX Font Info:    ... okay on input line 58.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 58.
LaTeX Font Info:    ... okay on input line 58.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 58.
LaTeX Font Info:    ... okay on input line 58.
LaTeX Font Info:    Checking defaults for PD1/pdf/m/n on input line 58.
LaTeX Font Info:    ... okay on input line 58.
\AtBeginShipoutBox=\box32
Package hyperref Info: Link coloring OFF on input line 58.

(/usr/share/texlive/texmf-dist/tex/latex/hyperref/nameref.sty
Package: nameref 2016/05/21 v2.44 Cross-referencing by name of section

(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/gettitlestring.sty
Package: gettitlestring 2016/05/16 v1.5 Cleanup title references (HO)
)
\c@section@level=\count179
)
Redoing nameref's sectioning
Redoing nameref's label
LaTeX Info: Redefining \nameref on input line 58.
LaTeX Info: Redefining \ref on input line 58.
LaTeX Info: Redefining \pageref on input line 58.
LaTeX Info: Redefining \nameref on input line 58.
LaTeX Info: Redefining \degres on input line 58.
LaTeX Info: Redefining \dots on input line 58.
LaTeX Info: Redefining \up on input line 58.
\myptabbox=\box33
\myptabboxwidth=\skip269
Package caption Info: Begin \AtBeginDocument code.
Package caption Info: listings package is loaded.
Package caption Info: End \AtBeginDocument code.
\c@lstlisting=\count180
LaTeX Font Info:    Try loading font information for T1+cmss on input line 60.
(/usr/share/texlive/texmf-dist/tex/latex/base/t1cmss.fd
File: t1cmss.fd 2014/09/29 v2.5h Standard LaTeX font definitions
) (./main.lol
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <12> on input line 1.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <8> on input line 1.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <6> on input line 1.
)
The widest listings number is: 23.49426pt
[1

{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}]
\tf@lol=\write4
\openout4 = `main.lol'.

Package atveryend Info: Empty hook `BeforeClearDocument' on input line 78.
Package atveryend Info: Empty hook `AfterLastShipout' on input line 78.
 (./main.aux)
Package atveryend Info: Executing hook `AtVeryEndDocument' on input line 78.
Package atveryend Info: Empty hook `AtEndAfterFileList' on input line 78.
Package atveryend Info: Empty hook `AtVeryVeryEnd' on input line 78.
 ) 
Here is how much of TeX's memory you used:
 12122 strings out of 493013
 180497 string characters out of 6135681
 308147 words of memory out of 5000000
 15584 multiletter control sequences out of 15000+600000
 8981 words of font info for 27 fonts, out of 8000000 for 9000
 1141 hyphenation exceptions out of 8191
 38i,9n,42p,247b,862s stack positions out of 5000i,500n,10000p,200000b,80000s
{/usr/share/texmf/fonts/enc/dvips/cm-super/cm-super-t1.enc}</usr/share/texmf/
fonts/type1/public/cm-super/sfrm1200.pfb></usr/share/texmf/fonts/type1/public/c
m-super/sfss2488.pfb>
Output written on main.pdf (1 page, 23230 bytes).
PDF statistics:
 32 PDF objects out of 1000 (max. 8388607)
 26 compressed objects within 1 object stream
 8 named destinations out of 1000 (max. 500000)
 1 words of extra memory for PDF output out of 10000 (max. 10000000)
3
  • Does this version compile for you as is? I get the same errors as in your original file when the listings are typeset.
    – siracusa
    Nov 7, 2019 at 5:38
  • 1
    @siracusa, of course. I compiled it with both MikTex and TexLive 2016 and no errors. I updated the question with the main.log.
    – user
    Nov 7, 2019 at 22:09
  • Sorry, the caption package wasn't updated properly on my system. It now complies fine for me too. That also makes the second patch from my answer redundant, only the \cftlstlistingname patch seems to be necessary.
    – siracusa
    Nov 7, 2019 at 23:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .