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 \detokenize macro of etex.

But this macro also make controlsequence character catcode to 12. It direct use create some bug in some specific case in reledmac (too complex here to explaine why).

What I would like is to transform the already read character with catcode 13 to character with catcode 12, but be able to read \ and so one, because I need them in a \edef definition.

Here a MWE



\expandafter\def\csname a\endcsname{toto}

%\edef\one{a \emph{ω a}}%That can't work

\edef\two{\detokenize{a \emph{ᾧ a}}}

\show\two%->a \emph {ᾧ a}
% What I would like is to set definition of two to
% a ᾧ a
% While ᾧ inactive character
  • with a current latex your old example in tex.stackexchange.com/q/244538/2388 works. Try it out (the implementation of active chars from inputenc have been changed here). – Ulrike Fischer Mar 4 at 18:27
  • Note you are using pdftex so you can not talk about being an active or not active character it is three characters, with codes hex E1 BE A7 If you make character hex E1 not active in the edef then this combination will never typeset as ᾧ when the macro is used. – David Carlisle Mar 4 at 19:09
  • @DavidCarlisle does not matter in my case, as the macro won't be used to typeset anything, it is only for internal use. – Maïeul Mar 5 at 10:14
  • @Maïeul well, it still matters in terms of what you are asking for and what answers you want as you asked for a detokenized non-active ᾧ but in the accepted answer what you have is a ᾧ made of three bytes as usual, all three of which have their standard active catcodes. – David Carlisle Mar 5 at 10:33
  • yeah, you are right. I was tired yesterday. In the past, I though the problem was with active character, but as I changed my internal code since this time, the problem is only with expansions of active characters, not with active characters directly. But you are right, my question title is not good. – Maïeul Mar 5 at 10:40

With a current latex you could use \protected@edef:



\protected@edef\two{a \emph{ᾧ a} \textbf{a}}


This gives:

> \two=macro:
->a ᾧ a \protect \textbf  {a}.
| improve this answer | |
  • Ho yeah! Thats is perfect ! – Maïeul Mar 5 at 10:13

First things first, \detokenize is an e-TeX primitive, not a macro. :-)

What about this?



\tl_new:N \g__maieul_tmp_tl
\cs_generate_variant:Nn \tl_to_str:n { e }

\NewDocumentCommand \myConversionFunc { m m }
      \clist_map_inline:nn { \emph, \textbf } % you can add more, of course
        { \cs_set_eq:NN ##1 \use:n }

      \tl_gset:Nx \g__maieul_tmp_tl { \tl_to_str:e { \text_expand:n {#2} } }
    \tl_set_eq:NN #1 \g__maieul_tmp_tl



\myConversionFunc{\result}{a \emph{ᾧ a}}

\myConversionFunc{\result}{a ᾧ \textbf{éêè }\emph{ᾧ a} Û}


Terminal output:

> \result=macro:
->a ᾧ a.
l.27 \show\result

> \result=macro:
->a ᾧ éêè ᾧ a Û.
l.30 \show\result

If this is not what you want, please explain what you meant with “but be able to read \ and so on, because I need them in a \edef definition.”

Note: \text_expand:n is a recent addition to expl3, as far as I know.

| improve this answer | |
  • I undeleted the (updated) answer. – frougon Mar 4 at 18:27
  • yeah, that is what I need. But i will look on Ulrike code, which is maybe simpler and enough for my need. – Maïeul Mar 5 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.