latex3 / babel

The babel system for LaTeX, LuaLaTeX and XeLaTeX
LaTeX Project Public License v1.3c
123 stars 34 forks source link

\addto adds unwanted whitespace in KOMA-Script \headmark #254

Closed Tikrass closed 11 months ago

Tikrass commented 11 months ago

Dear developers,

I found a strange behavior that I believe to be a bug. Unescaped line breaks in \addto add a space in the \headmark of KOMA-Script pagestyles.

\documentclass[english]{scrartcl}

\usepackage{scrlayer-scrpage}
\usepackage{blindtext}

\clearscrheadfoot
\ihead[\thepage]{{Something \headmark}}
\automark[section]{section}

\RequirePackage{babel}

\newcommand\testone{1234}
\addto\extrasenglish{
\renewcommand\testone{1234}
\renewcommand\testone{1234}
\renewcommand\testone{1234}
\renewcommand\testone{1234}
\renewcommand\testone{1234}
\renewcommand\testone{1234}
\renewcommand\testone{1234}
}

\begin{document}

\Blinddocument
\end{document}

example

This might affect also other locations, where the language is loaded midways. This could also be a bug in KOMA-Script, but I have not enough understanding how these two functions play together.

Removing the \renewcommand-lines or escaping the line breaks with a trailing % fixes that behavior.

In my humble opinion, line breaks and spaces should be neutral in the argument of \addto, as this macro is only used in the preamble and is not used to produce any printable output.

I use

This is LuaHBTeX, Version 1.17.0 (TeX Live 2023/Arch Linux)
Development id: 7581
u-fischer commented 11 months ago

you are adding spaces and should suppress them with % if you don't want them.

\addto\extrasenglish{%
\renewcommand\testone{1234}%
\renewcommand\testone{1234}%
\renewcommand\testone{1234}%
\renewcommand\testone{1234}%
\renewcommand\testone{1234}%
\renewcommand\testone{1234}%
\renewcommand\testone{1234}%
}

This is quite standard behaviour in macro definitions.

FrankMittelbach commented 11 months ago

Spaces inside a declaration such as this can't be suppressed because in certain places they are wanted, e.g., if you add something like \renewcommand\tocname{Table of Contents}. When TeX reads an argument of some macro the spaces becomes real individual spaces and thus when \extraenglish gets typeset you get several spaces (in your example) into the typeset stream and they all make individual spaces, they don't even merge into one, because that happens only when they are first seen by TeX and only if the are consecutive at that time (your's aren't).

jbezos commented 11 months ago

As already explained, this is the standard and expected behavior. Actually, \date<language> and \captions<language> do remove these spaces, because their purpose is strictly to redefine some macros (they shouldn’t produce any printable output, indeed), but \extras<language> is more for arbitrary stuff, so it won’t change.