0

This question already has an answer here:

My problem is as follows: I would like to obfuscate LaTeX code in a style file, so that others may be able to use some LaTeX commands I define, but are not able to see how they are defined. This issue has been raised already on stackexchange (for example Obfuscating TeX) but no real answer has been given. The example of the xii.tex file is very impressive and exactly what I need, but no information is given on the way this document has been obtained.

Does anyone know how I can convert code into something like xii.tex in an irreversible way?

marked as duplicate by Seamus, moewe, user13907, Mico, yo' Nov 19 '15 at 9:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Asking the same question again won't help. Why not post a bounty on the original question? – Seamus Nov 19 '15 at 7:57
  • 1
    xii.tex is not easy to read, but it is not very difficult either - you only need the texbook and some standard tracing commands. If you really want to hide the definitions you would need imho a special format. – Ulrike Fischer Nov 19 '15 at 8:07
  • As TeX's a macro expansion language, any odd naming can always be unpicked using \tracingall. Even if you deliberately disable that in your code, the user can just take precautions before loading. As @UlrikeFischer says, a format does allow you to hide stuff but is tied to the architecture it's built on (so same engine version is required to use it). – Joseph Wright Nov 19 '15 at 8:19
  • Concerning the duplicate, that was a network problem (for a few moments I had no network and apparently once the network was reestablished the question was created twice). Sorry! As for \tracingall, I don't mind about that, because somebody proficient enough in TeX to be able to understand \tracingall output, would be proficient enough to write my code in the first place. So what I really need is guidelines on how to write xii.tex-like TeX code, regardless of the possible interpretation through \tracingall... – yannis Nov 19 '15 at 8:44
  • 2
    @yannis recipe: open emacs buffer, drink coffee, write document. – David Carlisle Nov 19 '15 at 9:50
2

This is not really possible. TeX is a macro expansion language and the execution path of all code is available and may may be interrogated within the system.

xii is a complete plain TeX document. Some have (somewhat rudely!) described my TeX coding there as obfuscated, but it is completely reversible and if you search for xii on this site you will find at least a couple of answers where other people, just from the published file, have given step-by-step explanations of how the code works.

Of course if you just want to make it hard for the casual reader, not make something that is really irreversible then just doing the first stage of the xii coding, setting

\catcode`j=0

and using j instead of \ to escape command names, might be enough.

  • I'm glad David is alive! Thanks for the hint to look for xii on this site. Indeed I found Hendrik's answer (tex.stackexchange.com/questions/105808/…) and this I can use as a recipe. Of course, once you have defined j to be a backslash, you cannot have a j letter anymore, do you? How about using characters in the 8-bit range? And re-assigning catcodes randomly and often so that a global search and replace will not do? – yannis Nov 19 '15 at 9:20
  • @yannis j is jchar112, or even, jcharjnumexpr"e*8jrelaxjrelax or something like that (sorry I don't have LaTeX here). However, the key is to choose a letter you probably won't need. In Czech, this would be q, for instance. In English, it's j. – yo' Nov 19 '15 at 9:45
  • I'm playing around with it and it works, but there is one thing I don't manage to obfuscate: command names. Is there some way to define, for example, § to be e and £ to be n and é to be d, so that \§£é is read as \end? (maybe by using \expandafter, \csname and \endcsname?) – yannis Nov 19 '15 at 10:18
  • @yannis if the file is in utf8 probably not as they will be multibyte and things get complicated. (It would be easier if it were a unicode-aware tex:-) if the file is in latin1 (or any 8bit encoding then sure) just make § £ é all catcode 11 (possible as they are a single byte) and then \let\§£é\end – David Carlisle Nov 19 '15 at 11:21
  • @david I tried to use \global\expandafter\def\csname ÎÎÎ\endcsname{coucou}\nnn where Î is a catcode 13 character that expands to n, but it doesn't work: \csname will not expand what follows to get nnn as name of the command. Do you see a solution? What I want to do is to obtain "replacements" of [a-z] letters so that instead of writing clear command names, I can write \csname ...replacement characters... \endcsname and get the command without writing its name (cf. the example of \nnn above). – yannis Nov 19 '15 at 13:53

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