Sign up ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

By now I know how to make \textminus in tex4ht work, but this does not seem to be enough to display a proper minus with the \num macro of siunitx. Joseph Wright provided a workaround, but I'd like to know how to make this work at a more general level.



  +5 \homegrowntextminus 5

Is there a way to configure tex4ht so that it prints a proper minus sign (as in the pdflatex output below) when converting to HTML without knowing or modifying \homegrowntextminus?

+5 -5

GitHub MWE:

share|improve this question

1 Answer 1

up vote 5 down vote accepted

What was showed in textminus in tex4ht may be good for small changes, but correct process is different. Because textcomp is basically font selection package, existing tex4ht support is not done by redefining macros in textcomp.4ht file, but a special mapping file for font used by textcomp, tcrm.htf exists. It is located in texmf-dist/tex4ht/ht-fonts/unicode/jknappen/tc directory. You can copy this file to your working dir and edit it according to your needs.

These .htf files are used by tex4ht processor to convert glyphs in the dvi file to internal representation, which is then converted using .4hf files to actual characters.

Structure of .htf files is described in tex4ht help. We need to find position of \textminus in this file and correct provided definition. It corresponds to position in font encoding. textcomp package uses TS1 font encoding, which is defined in ts1enc.def. If we search for \textminus, we find this line:


This means that \textminus is defined on position 61 in the tcrm.htf file:

 '-' ''            61

as you can see, - is hardcoded here. We can modify that to use unicode minus instead:

 '−' ''            61

It is best to use this hexadecimal form, because it is used by .4hf files to convert to the actual character.

If you compile your file with htlatex textput now, and watch output of tex4ht command, you will see this line:


if you search this file for x2212, you will find line:

 '−' ''  '-' ''

this means that unicode minus is converted back to -. This is why this work only with unicode output with

 htlatex texput "xhtml, charset=utf-8" " -cunihtf -utf8"

different .4hf file is used now:


different definition is used there:

 '−' '' '\226\\136\\146\' ''

this converts entity to the unicode value.

Now back to this question, situation is simpler, as you have added your own symbol at position 61, where original \textminus is placed and which we already redefined. So this will work also for \homegrowntextminus.

share|improve this answer
Thank you so much for taking the time to derive the necessary steps and to explain them. It will help me and others in similar situations, and sheds some light on the internals of tex4ht. I do hope this can be applied to upstream tex4ht -- for my one-shot project, patching siunitx has turned out to be faster than patching three of tex4ht's files. – krlmlr Feb 27 '14 at 13:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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