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

trim whitespace in loading LaTeX classes and packages #2430

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dginev
Copy link
Collaborator

@dginev dginev commented Oct 14, 2024

Minimal example:

\documentclass[
	aps, pra]{revtex4-2}
\begin{document}
Hello world.
\end{document}

This leading \par in the options of \documentclass was the first encountered problem in a recent arXiv report, which turned out to be also related to a greek babel regression, reported in #2429 .

I took the opportunity to sanitize (by trimming whitespace) the options argument to \documentclass, \documentstyle, \usepackage, \RequirePackage, \LoadClass, \PassOptionsToPackage, \PassOptionsToClass, \ExecuteOptions.

This may be removed soon after in a world where we load all of latex.ltx raw, but I realized that only after completing the code changes. So filing the PR in any case, for your consideration.

@brucemiller
Copy link
Owner

This kinda screams for either a Trimmed type of argument, or at least that the option processing routines would trim their arguments.

@dginev
Copy link
Collaborator Author

dginev commented Oct 31, 2024

Done, thanks. I tried a couple of approaches, then realized the argument handling happens at different stages - some options are Tokens, others are already Boxes (typically a List). So doing the sanitization after the string phase is easier in the short run.

Parameter types could improve too, but OptionalTrimmedSemiverbatim seemed to be a mouthful.

@dginev
Copy link
Collaborator Author

dginev commented Oct 31, 2024

I also found 5 places in 5 bindings which can benefit from sharing this new helper function. I haven't committed them here yet, let me know if you'd like them added (in authblk, cleveref, elsarticle, enumitem and ntheorem).

@brucemiller
Copy link
Owner

Hmm (again). So actually all(?) of these are cases of keyval or option lists, but at a somewhat special top-level, which may not be quite the same as the usual keyval processing. And a 3rd hmm is that these are commands that call for special treatment anyway, so are likely to always need LaTeXML bindings even if we read latex.ltx. I wonder if some use or adaptation of OptionalKeyVals would be the best long-term approach?

@dginev
Copy link
Collaborator Author

dginev commented Nov 12, 2024

The parameter type name that resonates with me is PackageOptions, since the comma list convention is a top-level latex convention for classes and packages.

With that name we could even avoid the leading Optional, since they are always optional.

I am also wondering if we should be comparing to DirectoryList and CommaList here, rather than KeyVals.

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

Successfully merging this pull request may close these issues.

2 participants