following problem:

    \read\inputfile to \readline%



The input files contain special characters like "#", "$" and so on, as well as LaTex commands. I need to expand the LaTex commands on file read, all other special character should remain unchanged.

What I need is something like a

\detokenize{\catcode`\\=0 \readline}

which assigns all tokens except "\" a catcode of 12. Any ideas?

  • 2
    why use detokenize at all? just set the special characters to catcode 12 (eg \let\do\@makeother \dospecials would be enough) then set \\ back with \catcode`\\=0 – David Carlisle Nov 24 '16 at 8:55
  • Change the name \readline into something else, because \readline is a primitive. – egreg Nov 25 '16 at 8:48

I think that you're trying to write out a copy of some file, but with commands fully expanded.

You can do away with catchfile:

\foo{abc} #$% \foo{A}%



  \endlinechar=`^^J % when writing out, newlines will be preserved
  \catcode`\#=12 % so # makes no problem
  \catcode`\%=12 % so % is not a comment
  % maybe others





I don't think you really need other characters to be managed specially.

Here is the contents of the .out file after processing.

--abc-- #$% --A--%

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.