Skip to main content

Timeline for Passing parameters to a document

Current License: CC BY-SA 4.0

13 events
when toggle format what by license comment
May 28, 2023 at 14:40 comment added Bruno Le Floch Oops, you are completely right. If there is no command line argument there is nothing at all after the file ends (via \endinput), and there is no way to see that short of trying to read more tokens from the input stream and failing. Unfortunately that ends the run (in batchmode etc) or requests more input in an interactive run. It might be worth thinking about adding engine support for this use case if the other answers here are not suitable.
May 28, 2023 at 14:37 history edited Bruno Le Floch CC BY-SA 4.0
Fix comment
May 28, 2023 at 14:30 comment added user202729 Correction 2 (sorry): I just double check, turns out this still blows up when there's no argument (looks like it's intentional because of some historical artifact, paragraph 36 of texdoc tex source code gives some hints). At least now it can grab however many arguments there are on the command-line. An alternative is to \batchmode before and restore the interaction mode after, but this will terminate TeX if there's no argument no matter what I do.
May 28, 2023 at 14:12 comment added Bruno Le Floch Very curious indeed. I've fixed that by setting \endlinechar=13, to be future-proof in case this bug is fixed (or differs between engines).
May 28, 2023 at 14:11 history edited Bruno Le Floch CC BY-SA 4.0
Make code even more robust.
May 28, 2023 at 13:57 comment added user202729 It's always exactly ^^M regardless of endlinechar though. (curiously)
May 28, 2023 at 13:36 comment added Bruno Le Floch @user202729 Thanks, very useful comment, I've updated the code to take advantage of it.
May 28, 2023 at 13:36 history edited Bruno Le Floch CC BY-SA 4.0
Make code more robust.
May 27, 2023 at 15:18 comment added user202729 With some experiment I determine that an untokenized input character ^^M is used to terminate the argument, so that can be used to solve the situation where no argument is passed. (first used in tex.stackexchange.com/a/672229/250119) Also if it happens that the command-line argument starts with something expandable the \expandafter will have side-effect, \noexpand is safer, but this is even more academical...
Aug 5, 2018 at 8:47 comment added Bruno Le Floch @Gherardo: It is unfortunately not possible, as TeX actually provides no way of accessing command-line arguments. My answer above is really a hack that "works" in a very specific setting, not beyond.
Jul 31, 2018 at 7:11 comment added Gherardo I do like this solution, that's almost what I would need, uo to one point. If I pass a parameter, it works fine. If I do not pass any parameter, it stops with a tex prompt *. Could you be so kind to modify this solution to handle the case where no parametre is passed? Thanks in advance...
Aug 5, 2014 at 12:29 comment added emem It works, and it can even handle more command line options, but it is not easy to understand or manipulate (not straightforward for people who are less familiar with LaTeX)
Aug 14, 2011 at 21:36 history answered Bruno Le Floch CC BY-SA 3.0