My code:

hello \world{}

I compile this with make4ht like this:

$ make4ht foo.tex        
[STATUS]  make4ht: Conversion started
[STATUS]  make4ht: Input file: foo.tex
[STATUS]  make4ht: Conversion finished

Here is the generated HTML:

<!DOCTYPE html> 
<html xml:lang='en-US' lang='en-US'> 
<meta charset='utf-8' /> 
<meta name='generator' content='TeX4ht (https://tug.org/tex4ht/)' /> 
<meta name='viewport' content='width=device-width,initial-scale=1' /> 
<link type='text/css' rel='stylesheet' href='foo.css' /> 
<meta name='src' content='foo.tex' /> 
<!-- l. 4 --><p class='noindent'>hello world </p> 

Can I tell make4ht or tex4ht or htlatex to output raw HTML at some places I need? For example, I want that whenever I invoke the new command \world, it is wrapped with <span> tag around it like this: <span class="keyword">world</span>.

In other words whatever currently appears as merely world in the HTML output should appear as <span class="keyword">world</span> in the HTML output. Can this be done? If yes, can you please provide a minimal working code that shows how this can be done?

1 Answer 1


You can redefine your \world command in a custom .cfg file. Try this configuration file:

% save original contents of the \world macro
\renewcommand\world{\HCode{<span class="keyword">}\orig@world\HCode{</span>}}

We save the original \world macro in \orig@world. This way, you can stay synchronized with your LaTeX file, and when you decide that \world should produce something different than string "world", you don't need to change this configuration. You can then redefine \world to use \HCode commands to insert the HTML code, and the saved \orig@world to produce the "world" text.

compile using:

make4ht -c config.cfg samle.tex

This is the result:

 <p class='noindent'>hello <span class='keyword'>world</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.