Take the 2-minute tour ×
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.

Is there a way to make tex4ht aware of the \textminus command?

\documentclass{scrartcl}
\usepackage{textcomp}
\pagestyle{empty}

\begin{document}
  \textminus 5
\end{document}

works as expected with pdflatex --- -5 --- but creates a simple hyphen when converting to HTML using

mk4ht htlatex texput.tex "xhtml,bib-"

I'd like it to print a Unicode minus sign instead; I can print an em rule by saying

\def\textminus{--}

in the preamble, but I understand that an em rule is something different than a minus sign.

The MWE is also at GitHub, use make texput.html after checking out the tex4ht-textminus branch to generate HTML output.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

There is no configuration for textcomp, so you can provide your own file with suitable redefinition of \textminus.

Create file textcomp.4ht and place it to directory with your document:

\renewcommand\textminus{\HCode{&\#x2212;}}

this will output hexadecimal html entity of minus sign. This entity will be later replaced by tex4ht command to other character, so it is important to output your file in unicode, because in default case, it is converted back to the - char!:

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

edit

More detailed and more correct setup is described in Redefine output for a specific TS1 code point (=glyph?)

share|improve this answer
    
Thanks! Actually, I'm targeting ooffice, so I don't need to care about UTF-8 anymore, right? Can I define this also in a .cfg file? –  krlmlr Feb 20 at 11:59
    
I've also seen on the minus sign page that the HTML entity − is equivalent to the hex code; would that still need the UTF-8 encoding? –  krlmlr Feb 20 at 12:11
    
@krlmlr yes, you can use this also in the cfg file –  michal.h21 Feb 20 at 12:22
    
@krlmlr in the case of −, I am not sure if it is supported by all viewers, particularly if you are interested in ooffice. but you can try it. in that case you don't need utf-8 encoding –  michal.h21 Feb 20 at 12:24
    
The − literal does work with HTML output, but LibreOffice fails to display it. The explicit Unicode character code works in LibreOffice; for HTML output, it requires the UTF-8 switches as you suggested. Thanks again. I've pushed the fixed MWE to the tex4ht-textminus-fix branch. -- Any chance this could be made part of upstream tex4ht? –  krlmlr Feb 20 at 13:26

Your Answer

 
discard

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.