Questions tagged [detokenize]

The e-TeX primitive `\detokenize`, which removes special meaning from TeX code.

Filter by
Sorted by
Tagged with
0 votes
0 answers
34 views

Tokenize a detokenized newcommand - NEWCOMMAND/DETOKENIZE Conflict

The problem is very simple to understand. I have 2 folders: document.tex abc.tex (this file needs to be unchanged, which means, \detokenize must be a part of it) document.tex: \documentclass{article}...
Bilal Yilmaz's user avatar
0 votes
1 answer
48 views

\detokenize in bookmark create strange characters

I want to have the math symbols in section titles automatically be converted into plain text in bookmarks. I find this answer and it does clear the "token not allowed in a pdf string" ...
Gau-Syu's user avatar
  • 463
3 votes
2 answers
184 views

Understanding scantokens

I am trying to work with \scantokens, but apparently, I don't really understand it. I want to detokenize some sequence into a register \S: \let\ea\expandafter \newtoks\S \ea\S\ea{\detokenize{\textbf{f}...
Bubaya's user avatar
  • 2,247
0 votes
0 answers
24 views

Unwanted Extra Spaces in \newcommand and \detokenize for Verbatim Text [duplicate]

I'm trying to make a newcommand to print verbatim text using the \detokenize as follows: \newcommand{\texcmd}[1]{% {\color{red!70}{\texttt{\detokenize{#1}}}} } When I use it to typeset a long ...
Ammar Taha's user avatar
0 votes
2 answers
67 views

How to save a macro to a file, unexpanded?

I want this to work, but it doesn't: \documentclass{article} \begin{document} \newcommand\hello{Hello, \LaTeX!} \newwrite\foo \immediate\openout\foo foo.tex \immediate\write\foo{\hello} \immediate\...
yegor256's user avatar
  • 12k
5 votes
1 answer
143 views

jobname, ifdefstring, IfSubStringInString, detokenize

My question is originally the same as use jobname to "pass parameters"? But that particular question doesn't seem to have a complete answer. (I'm sure that in the minds of experts who deeply ...
Ryo's user avatar
  • 871
0 votes
2 answers
530 views

Treat command provided as argument as plain text

I find myself struggling with a supposedly simple task but after several hours of searching and trial&error I finally give up. I probably still lack the deeper understanding of LaTeX and its ...
Johnson's user avatar
  • 227
0 votes
4 answers
76 views

How to get rid of a spaces after tokens in \detokenize?

Here is the code: \documentclass{article} \catcode`|=\active \def|#1|{\texttt{\detokenize{#1}}} \begin{document} Hello, |\a\b|! \end{document} It renders as such: The spaces after tokens are a ...
yegor256's user avatar
  • 12k
2 votes
1 answer
105 views

detokenize produces an undesired space after command sequence

I made a simple macro called \cmd{} which detokenizes the input. I would like to print the contents exactly as shown, and it works as I desire, except that it seems to produce a space between an ...
likethevegetable's user avatar
5 votes
2 answers
226 views

How can I expand or detokenize a macro before using it in a hyperlink?

So I have some information stored in a macro that is used already elsewhere and can contain formatting macros like \small or similar and I want to expand or detokenize those commands before also using ...
TobiBS's user avatar
  • 5,230
0 votes
0 answers
91 views

Detokenize input to \newcommand

I would like to define a command that removes .m when referencing to the caption generate_simdata.m (i have a lot of such matlab function files, and would like to reference them normally with \nameref ...
justsome631's user avatar
0 votes
2 answers
41 views

Escaping LaTeX tokens in addresses for printing one label printer that can cut

I am trying to print addresslabels on a Brother_QL_820NWB, which is a label printer, that can cut the paper. I have a small script, that gathers the address data from user input and than calls my ...
FFT2911's user avatar
  • 51
2 votes
0 answers
121 views

Mintinline in Tabularx / remove space in detokenize

I write a LaTeX manual in memoir class with the Minted package, TeXlive 2021 and TeXmaker. To insert some \mintinline code in a Tabularx X-type column, I used this trick and it work. Except that it ...
Bruno Douchy's user avatar
2 votes
1 answer
147 views

How do I detokenize '\texttt{%>%}'

I have a command: \newcommand{\help}[2]{ \href{https://www.rdocumentation.org/packages/#1/functions/#2}{\texttt{?\detokenize{#2}}} } and another \newcommand{\code}[1]{\texttt{\detokenize{#1}}} ...
mk9y's user avatar
  • 299
0 votes
2 answers
105 views

Reduce the length of underscore inside detokenize

Like this question But because many of my keywords has underscore, I created a macro called \keyword with \detokenize to make things easy. However, it makes underscore become longer again. \...
Qiang's user avatar
  • 184
2 votes
1 answer
141 views

Using \detokenize and underscore in combination with \listoffigures

I've been using a macro X similar to \newcommand{\X}[1]{{\ttfamily{\detokenize{#1}}}} to format certain words that may contain an underscore, without having to escape with \_. This worked until I ...
apriori's user avatar
  • 943
1 vote
2 answers
126 views

detokenize only active character

Few year ago, I asked a question about the best way to make active character inactive, in order to solve an issue with reledmac. inputenc, active catcode and \csnsame The answer was to use \...
Maïeul's user avatar
  • 11k
2 votes
1 answer
112 views

Hyphenate word with detokenized underscores

I want to write clean underscores without backslashes and hyphenate words by underscores. I tried to use underscore package, but it doesn't work with clean underscores and also breaks ...
Shalom Alecheim's user avatar
2 votes
1 answer
121 views

Seqsplit with detokenize get an error

I want to write some words with underscores inside table cells. It would be better if these words could be written without using \_ to get underscore. Also I want to make these word hyphenate in any ...
Shalom Alecheim's user avatar
5 votes
2 answers
375 views

Alternative to detokenize working with special unicode characters

I have defined new command using \NewDocumentCommand which represents description of node in graph. This contains name (provided as argument), some text description (provided as argument) and links to ...
user224348's user avatar
7 votes
4 answers
700 views

Expand multiple math-tokens before detokenize

I am a long time Latex user and over the last few weeks I am involved in a project that needs to do the following: I want to put in verbatim some math latex code that may include user-defined macros. ...
MBerra's user avatar
  • 73
2 votes
2 answers
449 views

Change size of underscore in detokenize

My question is closely related to this one. The solution there works fine for text, but here is my scenario. I want to typeset the names of all packages specially, so it is clear what I refer to. For ...
Ciprian Tomoiagă's user avatar
2 votes
2 answers
263 views

How to perform a replacement on a string before doing a \write?

I'd like to output LaTeX code to a file, with the caveat that all backslashes are doubled (ie, \ is replaced with \\). This output will be consumed by another program. I've adapted egreg's answer ...
MBlanc's user avatar
  • 123
2 votes
1 answer
484 views

Hyphenation after _ underscore in an detokenized string

Context: In my document, I use a citation mechanism for personal references. I defined a \citeref{} macro that processes a comma-separated list of arguments. The latter have following structure: ...
ebosi's user avatar
  • 11.7k
3 votes
1 answer
1k views

Automatic Labels with automatically generated keys

I am writing a collection of documents in book form, one each for 4-5 topics. Each book has upwards of 30 chapters each in a different file. The books must be able to cross reference each other since ...
magguu's user avatar
  • 917
2 votes
1 answer
2k views

Special cents notation in currency

I made a code that has a special way to write the cents. Here's a MWE: \documentclass{article} \usepackage{graphicx} \makeatletter \newif\if@thecomma \def\normal@comma{,} { \catcode`\,=\active \...
Fabricio Pio's user avatar
  • 1,021
3 votes
1 answer
328 views

Detokenize does not produce the expected underscores

I have a Knitr document where I sometimes have to escape underscores. The underscores are actually part of the original data, get loaded in R, and at some point knitted into the LaTeX code, so ...
rumtscho's user avatar
  • 989
4 votes
1 answer
203 views

omit spaces inside macro

I'm trying to understand why I can get LaTeX to ignore spaces inside text, but when I do the same thing inside a macro, it fails to ignore those spaces. I use \catcode32=9 to ignore ASCII space chars....
Mike Maxwell's user avatar
4 votes
1 answer
185 views

Exception for detokenize

following problem: \openin\inputfile=#1% \loop% \read\inputfile to \readline% \unless\ifeof\inputfile% \global\edef\filecontent{\filecontent\readline^^J}% \repeat% \closein\inputfile% ...
Denis's user avatar
  • 41
6 votes
2 answers
1k views

How can I check if the value of a variable is the same as what another variable?

My question is simple but I don't know any simple solution for it. I have an unknown variable namely \unknown and a variable which I want to compare \unknown with it, namely \test. I want a command ...
Omid Ghayour's user avatar
1 vote
1 answer
219 views

Expand argument for detokenize while creating index

After reading this answer https://tex.stackexchange.com/a/292362/64189, i'm trying to use it for my index. \newcommand{\ukindex}[2][\imki@jobname]{% \index[#1]{\detokenize{#2}}% } But i need to ...
Yola's user avatar
  • 481
2 votes
2 answers
214 views

How to obtain the string é by using the \detokenize command?

I failed to use "\include" with a file that contain the string "é" in its name like "réserve". so I tried the following without success \include{\detokenize{réserve}} After some trials I have ...
Hafid Boukhoulda's user avatar
5 votes
2 answers
758 views

Why does \detokenize # sometimes fail inside of environments?

When I use the pound sign/number sign/hash sign # inside of commands and environments, this refers to arguments. However, shouldn't \detokenize{#} make it NOT an argument? Situation The pound sign ...
Jonathan Komar's user avatar
0 votes
1 answer
218 views

Breaking Typewriter-styled Detokenized Text

The goal is to have snake_cased elements typewriter-styled breaking properly. I am using \detokenize rather than simply \_ because otherwise the snake_casing looks wrong, namely like this: rather ...
sunless's user avatar
  • 319
3 votes
2 answers
266 views

Use of mfirstuc with catcode 12 characters

I am trying to have my document read its own filename (which is known to be words and numbers separated by hyphens) and parse it. For everything after a certain hyphen, I want to replace the hyphens ...
adamglesser's user avatar
9 votes
1 answer
328 views

Somewhat versatile usage of \@gobble and \@firstofone found in several macros

I was doing search about my question (see here for more detail) and found a thread commath and \ifinner. In the thread, there is a macro named \spx , the definition and usage of which are extracted ...
Merzong's user avatar
  • 589
3 votes
1 answer
98 views

Surprising result with "fontenc" when \detokenize is applied to `-`

Whether \detokenize is applied to - or -- under the fontenc package T1 fonts the results are the same. \documentclass[border=10pt]{standalone} \usepackage[T1]{fontenc} \usepackage{lmodern} \begin{...
A.Ellett's user avatar
  • 50.5k
7 votes
2 answers
1k views

How to typeset the percent symbol inside \detokenize?

I am writing some personal notes about R programming. I defined a macro to typeset R functions and operators using a different font style and color: \newcommand{\rtext}[1]{% {\texttt{\detokenize{#1}...
I Like to Code's user avatar
2 votes
2 answers
147 views

Expand \def value from optional default argument? - Bug in \oldacronym (glossaries v4.02) - first use not respected and funny effects? [closed]

Edit: Bug only in glossaries v4.02. -> Update! \edef\args{[#4]{#1}{#2}{#3}}% \expandafter\newacronym\args% may be a way to expand unexpaned args. Is there a bug in the glossaries Package? ...
Koni's user avatar
  • 226
12 votes
1 answer
353 views

What could go wrong if I don't use \detokenize when creating macro names using macro arguments?

I was in correspondence with the author of a LaTeX package in which I volunteered code similar to the following (I have anonymised it so that it is not obvious what package): \makeatletter \...
Hammerite's user avatar
  • 3,586
7 votes
1 answer
1k views

Strange behaviour with \detokenize and underscore

I just learned about \detokenize, so this question is likely a naive one. Nonetheless, based on what I thought that I understood about \detokenize, I would have expected \detokenize{_} to render as _....
Adam Liter's user avatar
  • 12.5k
11 votes
2 answers
3k views

Use detokenize with command line input that has underscores

I'm calling a script where I give a command line input to LaTeX: pdflatex "\def\myvar{given_test} \input{figures.tex}" And then in the script, I try to use this "given_test" input and print it: \...
Leon palafox's user avatar
4 votes
1 answer
383 views

The command \string does not print curly braces of its argument

While printing the List of Symbols, I would like, in a draft, to print the definition commands as well. For instance, consider the following commands: \providecommand{\perm}{\ensuremath{\pi}} \...
Daniel Langr's user avatar
7 votes
1 answer
979 views

Can I use \begingroup \endgroup as delimiter of \detokenize, instead of {}?

I would like to use other delimiters than {} for the argument of \detokenize. E.g. something like \detokenize\begingroup a lot of stuff \com \mycom \endgroup but it does not work. Am I really ...
Loic Rosnay's user avatar
  • 8,157
17 votes
3 answers
3k views

Removing a backslash from a character sequence

For indexing I wanted to write a macro \macroname that removes leading backslashes from macro names but leaves the names of environments untouched. That is \macroname{\relax} --> relax \...
5gon12eder's user avatar
3 votes
2 answers
2k views

How listing and verbatim do to escape special character?

I use one macro to display text using texttt style. For the moment this macro is very basic. For example, if I want to use the character _, its catcode must be changed. Is there a clever way to ...
projetmbc's user avatar
  • 13.8k
47 votes
2 answers
17k views

What are the exact semantics of \detokenize?

How does \detokenize work? The e-TeX Short Reference Manual states: When followed by a <general text>, expands to yield a sequence of character tokens of \catcode 10 (space) or 12 (...
ipavlic's user avatar
  • 8,091