Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\label must directly follow preceding control sequence without newline in between #20

Open
Holzhaus opened this issue Mar 26, 2022 · 3 comments

Comments

@Holzhaus
Copy link

Before:

\section{foo}\label{sec:foo}

After reformatting:

\section{foo}
\label{sec:foo}

Although it looks nicer, this actually introduces a bug. Because the newline is treated as a space, it's possible that the space does not fit on the same page, which means that the \label ends up on the next page (resulting in a wrong page number).

@siefkenj
Copy link
Owner

How frustrating...do you have an example of a document where this happens?

@Holzhaus
Copy link
Author

Nope, but chktex warns about this. It'm getting warnings after reformatting:

% original.tex
\section{Hello}\label{foo}

Lorem ipsum dolor sit amet.
$ chktex original.tex
ChkTeX v1.7.6 - Copyright 1995-96 Jens T. Berger Thielemann.
Compiled with POSIX extended regex support.
No errors printed; No warnings printed; No user suppressed warnings; No line suppressed warnings.
% reformatted.tex
\section{Hello}
\label{foo}

Lorem ipsum dolor sit amet.
$ chktex reformatted.tex
ChkTeX v1.7.6 - Copyright 1995-96 Jens T. Berger Thielemann.
Compiled with POSIX extended regex support.
Warning 24 in doc.tex line 2: Delete this space to maintain correct pagereferences.
\label{foo}
^
No errors printed; One warning printed; No user suppressed warnings; No line suppressed warnings.
See the manual for how to suppress some or all of these warnings/errors.

@siefkenj
Copy link
Owner

siefkenj commented Mar 27, 2022

I'll have to think about this. I don't think chktex is right here. A \section should be strongly glued to the next paragraph so they should end up on the same page. Even if they don't end up on the same page, I think there's a fair argument that the link serves the reader best pointing to the start of the content of the section rather than the section heading.

The only place I could see this going wrong is if there were a bunch of blank sections in a row. The sections headings wouldn't be glued to each other, so maybe this pushes the pageref to the other side?

In any case, I can also see how it's annoying to pretty-print code and suddenly get chktex warnings.

As a temporary workaround, you should be able to do

\section{foo}%
\label{bar}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants