Can I define a command that takes an argument but does not eval the argument?
|
Ok, it seems that you mean the so called verbatim mode as "does not eval the argument". This is done in TeX by changing the category codes, short catcodes, of the special characters. This is done using The normal way to do is (1) change the catcodes in a group (2) call a second macro which reads the argument and closes the group (3) process the argument and read further arguments if required.
LaTeX helps here a little and provides
Update 2011-07-27:I now published a new version of |
||||
|
|
|
To answer the clarification of the question in the comments, this seems to work (though I'm no expert on the
|
|||||||||||||
|
|
I posted this already on Dick's blog. I think there is an easier way to do what Dick wants to do (if I understand him correctly) by using the
Edit: This does not treat special characters in URLs correctly. But this seems to work (using
|
||||
|
|
|
Just a point of clarification supporting Martin's answer, together with an attempt to put the behaviour in more of a programming language theory context and address some points in your weblog. The problem here is the highly dynamic staged approach Tex takes to its input, described by Knuth in terms of an analogy with the digestive tract. Tex takes its input a character at a time as it evaluates and "looks" at them with its "eye" - what happens at this stage is that the characters get catcodes. Expansion is the next thing that happens to these tokens, when they are "chewed" by its "mouth". At the time a macro "takes" an argument, it assigns catcodes ahead enough that it has all of the argument: you can't avoid this, but you can change the catcodes before this happens. Martin's answer uses his package to change the catcodes to all be letters (I think), so that the URL can be treated as a normal string when the argument is read in. If the set of valid Tex programs are those that terminate by executing the command behind the Knuth has never been one for the kind of discipline advocated by software engineers. Indeed, he weighed into the discussion following Dijkstra's "Goto considered harmful" paper with an opinion along the lines that goto is fine, even a good thing, if you know what you are doing (Knuth, 1974, "Structured Programming with go to Statements", Computing Surveys 6: 261–301). I guess the real problem with this style of programming is that it does not scale: two Knuths are not going to collaborate well. Tex is not entirely eccentric as a programming language. It can be considered as a child of Strachey's GPM. But none of the other GPM-derived languages I've seen are routinely used with such a drastically dynamic approach to syntax. |
|||||||
|
\verb|some $%^& text|. However this doesn't work when\verbitself is an argument of another macro. – Martin Scharrer♦ Mar 5 '11 at 16:03\newcommand{\commandname}[1]{definition}takes an argument but doesn't evaluate it if you don't use#1within thedefinitioncode. – Stefan Kottwitz♦ Mar 5 '11 at 16:08