Tag Info

Hot answers tagged

20

\task takes one argument, passing it to \@task which is defined in such a way that its arguments are delimited; if the call is \@task xyz:AB:cde:u\@nil the first argument is xyz, the second is AB and the third is cde:u. Here \@nil doesn't mean anything, it's just required by the syntax of \@task and TeX throws it away. \relax is a primitive of TeX, its ...


17

The \detokenize primitive converts all of its input into category code 12 ('other') tokens, except for spaces which stay as category code 10 ('space'). It is used to convert tokens into strings. For example, if we have \detokenize{\foo} then \foo would be a control word, i.e. one token, which is converted into 5 string characters (\, f, o, o, ), all which ...


13

If you have \catcode`\!=\active \def!{\hspace{2in} \fbox{boo} \hspace{2in}} then \csname foo!\endcsname is an error as the name doesn't expand to a sequence of character tokens, but \csname\detokenize{foo!}\endcsname is same as \csname foo\string!\endcsname and makes the token with name foo!


11

TeX works with tokens, and what you need to know is that a control sequence such as \foo is not tested by \if as a series of characters, but as a single 'unit'. There a a few primitives that will turn control sequences back into single tokens: \detokenize does this for a set of tokens, while \string does so for a single token. The latter is also available in ...


10

Joseph has given a working solution. I'd like to explain what goes wrong with your code. First attempt \newcommand\removebs[1]{\if#1\char92\else#1\fi} \newcommand\macroname[1]{% \expandafter\removebs\detokenize{#1}} With \macroname{\relax} you get \expandafter\removebs\detokenize{\relax} and then (using • to separate tokens and <space> do ...


8

TeX will allow you to use implicit { and } tokens in some places: these are available as \bgroup and \egroup. The \detokenize primitive is toks-like, and so will accept an implicit begin-group token \detokenize\bgroup stuff} \bye but requires an explicit end-group token (as shown). \begingroup/\endgroup forms a 'semi-simple' group, which is not the same ...


7

Together with guidelines in Handling of special LaTeX characters in text, you can expand \myvar before \detokenize-ing it: \documentclass{article} \usepackage[T1]{fontenc}% http://ctan.org/pkg/fontenc \def\myvar{given_test} \begin{document} \textbf{filename: \detokenize\expandafter{\myvar}} \end{document}


6

\string only takes one token and prints that, so it only ever sees \permel. Try \providecommand{\symbdef}[2]{\texttt{\color{blue}\detokenize{#1}} & #1 & #2} This will insert explicit spaces after control sequences, which is not semantically wrong, but might not be aesthetically pleasing. In that case, try filtering out the spaces like this: ...


4

It shouldn't be difficult to change your pipeline to do pdflatex "\edef\myvar{\detokenize{given_test}}\input{figures.tex}" Example with figures.tex like this: \documentclass{article} \begin{document} Here's the file name: \texttt{\myvar} \input{\myvar} \end{document} and with given_test.tex containing Hello World! Compiling with the above ...


3

Usually you change the catcode first and then read the argument. Direct after reading the argument you can close the group and end the temporary catcode change: \newcommand\breakabletexttt{% \begingroup \catcode`\_=12 \@breabletexttt } \newcommand\@breabletexttt#1{% \endgroup % do something with #1 which now contains `_' with catcode 12 ...


3

\verb and verbatim use the list stored in \dospecials. The most complicated part in their definition is how to end them which is rather tricky as \ and } no longer work. In simple cases you can use simply another char like ] as end of group: \documentclass{article} \usepackage[T1]{fontenc} \begin{document} {%a new endgroup char: \catcode`\]=2 ...


1

As Qrrbrbirlbel points out in the comments, there is no _ in OT1 encoding, which is the default font encoding for LaTeX. Yet, in T1 encoding, _ is at 5xF: Which is where ˙ is at in OT1 encoding: Thus, without specifying the output font encoding to be T1 by declaring \usepackage[T1]{fontenc} in the preamble, the output will be ˙ instead of _.



Only top voted, non community-wiki answers of a minimum length are eligible