I'd like to add TeX4ht support for my package, which is written in LaTeX3.

Is it safe to switch \ExplSyntaxOn inside a .4ht file? Should I switch it off at the end?

If it was NOT safe, how should I proceed to redefine (in classic syntax) a macro that has a LaTeX3 name (with underscores)

  • 2
    A short sample file would help us be more specific in our answers. – musarithmia Jan 6 '15 at 20:07
  • What @AndrewCashner says, without a minimal (non)-working example (MWE) it's difficult to see what you mean, with the MWE, you'll likely find out what works and what does not ;) – yo' Jan 6 '15 at 20:24
  • Of course, I tested with a MWE. But my question was not "Does it work or not?". My question was "Is it safe?", meaning "Is it a good idea to do so? Or does it have side effects that could break things in complex scenarios?" – mh378 Jan 8 '15 at 9:46

\ExplSyntaxOn and \ExplSyntaxOff are smart commands and restore catcodes of redefined characters to their previous values, so it is safe to use them even in .4ht files, where : has catcode of letter. We can test it with following package, hello.sty:


\DeclareDocumentCommand\hello {m}{

\cs_new:Npn \hello:n #1{hello\ LaTeX3:\ #1}


\def\sample{old sample}

two document commands \hello and \sample are defined, one using LaTeX3 features, the second with plain \def, just to show that it works, which we can test with this configuration file, hello.4ht:



\cs_set:Npn \hello:n #1{\a:hello hello\ tex4ht:\ #1\b:hello}

\Configure{hello}{\HCode{<span class="hello">}}{\HCode{</span>}}

\Configure{sample}{\HCode{<span class="sample">}}{\HCode{</span>}}

\hello is redefined to print text "hello tex4ht:and content of two hooks, which are later configured to insertspanelement withclass=helloattribute. To show thattex4htcommand works as usual,\sampleis redefined as well,\pend:defand\append:def` insert content at the beginning and at the end of the redefined macro.

Now we can show some test document:


\hello{world} and \sample

and result:

<!--l. 5--><p class="noindent" ><span class="hello">hello&#x00A0;tex4ht:&#x00A0;world</span> and <span class="sample">old sample</span></p>

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.