Is there an easy way to let LaTeX ignore parts of the argument to a \section command when writing the .aux file?
Example:
\documentclass[halfparskip]{scrartcl}
\usepackage{lastpage}
\newcommand*{\points}[1]{%
\noindent%
\raggedright%
{\nobreak\hfill\penalty50\hskip1em\null\nobreak%
\hfill#1 Points%
\parfillskip=0pt \finalhyphendemerits=0 \par}%
}
\renewcommand{\thesection}{Question \arabic{section}:}
\begin{document}
\section{Testing a test \points{4}}
Lorem Ipsum and so on. This is just a longer text that is meant
to fill the space. The actual text is not relevant for this question.
\end{document}
With the lastpage package loaded, compilation fails because of the \par in the .aux file generated:
(./minimal.aux
Runaway argument?
{{1}{1}{Testing a test \noindent \protect \raggedright {\protect \nobreak \ETC.
! Paragraph ended before \@newl@bel was complete.
<to be read again>
\par
l.4 ...rfillskip =0pt \finalhyphendemerits =0 \par
}}{}{}}
This problem could be fixed by modifying the macro "points" to avoid writing "\par" and perhaps a few other commands to the aux file. The "\par" command is there to fix that with the "halfparskip" option of Scrartcl, the "\hfill" does not fill all the way to the end, which is a suggested solution at Trouble with \hfill not going to the end of the page. This admittedly unclean solution also works when not including the "lastpage" package, which is however needed in the actual document of interest (and not this minimal non-working example).
I am aware that defining an alternative command to "\section", receiving two parameters, of which only one will go into the outline, is probably the cleanest way, but they may be harder to maintain after changes to other packages if there is a more simple way to ignore "3 points" when writing the .aux file.
Testing a test\texorpdfstring{\hfill 3points}{}
aux
file, but theout
file.\NewDocumentCommand{\points}{m}{%
.