# tex4ht turning the unbreakble space by ~ into unbreakable space in the html

Following my problem concerning spaces from unbreakable (thin) space inside « », for tex4ht

I edited my message with the following use of the working trick from @michal.h21

\ifx\HCode\undefined \else
\usepackage{newunicodechar}
\def\mythinspace{\HCode{<span style="white-space:nowrap">&thinsp;</span>}}
\newunicodechar{«}{«\mythinspace\ignorespaces}
\newunicodechar{»}{\unskip\mythinspace»}
% \newunicodechar{;}{\mythinspace;}
% \newunicodechar{:}{\mythinspace:}
\fi
\begin{document}
\ifx\HCode\undefined \else
\Css{body{background-color:gainsboro;}}
\Css{.fine{
display: inline-block;
width:0.125em;}
}

\catcode\!=\active%
\catcode\:=\active%
\catcode\;=\active%
\def\insertthinspace#1{%
\def#1{\unskip\mythinspace\detokenize{#1}}%
}
\insertthinspace! \insertthinspace: \insertthinspace;
\fi


the trick works well, but if I use a numerical code such as &#8201; for thin space, instead of its name &thinsp; in the modified trick,

\def\mythinspace{\HCode{<span style="white-space:nowrap">&#8201;</span>}}


then the make4ht outputs an error:

(d:/texlive/texmf-dist/tex/latex/newunicodechar/newunicodechar.sty)
! Illegal parameter number in definition of \mythinspace.
8
l.29 ...{\HCode{<span style="white-space:nowrap">&#8
201;</span>}}
?


QUESTION 1 : is it possible to enter a numerical name in the definition of \mythinspace ?

QUESTION 2: is it possible to turn every ~ from my .tex used as a thin non breakable space, into a

<span style="white-space:nowrap">&thinsp;</span>}


in my .html ???

For instance, there is also the case of the long dash --- which must have a non breakable space inside it. I attempt to replace the tilde by

\catcode\~=\active%
\def\~{\unskip\mythinspace\ignorespaces}%


but of course it no longer shows the tilde when I need one: Try to compile the code below with active the replacement of the tilde.

    \textemdash~my text in long dash~---\\
---~asdmy text in long dash~\textemdash

\~{n}ana un tilde \~{}.

\char\~


you see that the tilde disappears. even worse, the .html does not show a replacement of the tilde with the thin non-breakable space

<!--l. 202--><p class="noindent" ><span
class="cmr-12">—</span><span
class="cmr-12"> my text in long dash</span><span
class="cmr-12"> —</span><br
class="newline" /><span
class="cmr-12">—</span><span
class="cmr-12"> asdmy text in long dash</span><span
class="cmr-12"> —</span>
</p>
<!--l. 205--><p class="noindent" ><span style="white-space:nowrap">&thinsp;</span><span
class="cmr-12">nana un tilde</span><span style="white-space:nowrap">&thinsp;</span><span
class="cmr-12">.</span>
</p>
<!--l. 207--><p class="noindent" ><span
class="cmr-12">˜</span>
</p>


So is it possible to turn every ~ from my .tex used as a thin non breakable space, into a

<span style="white-space:nowrap">&thinsp;</span>}


in my .html while keeping intact the use of ~ when it is used normally, like for accents in \~{o} ???

1) yes, it is, but you must enter it as hex value:

\def\mythinspace{\HCode{<span class="fine">&\#x2009;</span>}}


# character must be escaped using \#. Note that this numerical entity is later replaced with actual unicode character in the HTML. You can revert it with custom unicode.4hf file

2) ~ is already active character, you can redefine it using:

\def~{\unskip\mythinspace\ignorespaces}%


(so no \~)

Complete sample document:

\documentclass[oneside,a4paper, 12pt]{article}
%\usepackage[french]{babel}
%\usepackage[style=french]{csquotes}%
\usepackage{alternative4ht}
\altusepackage{polyglossia}
\altusepackage{fontspec}
\setdefaultlanguage{french}

\ifx\HCode\undefined \else
\usepackage{newunicodechar}
\def\semicolon{\detokenize{;}}
\def\mythinspace{\HCode{<span class="fine">&\#x2009;</span>}}
\newunicodechar{«}{«\mythinspace\ignorespaces}
\newunicodechar{»}{\unskip\mythinspace»}
% \newunicodechar{;}{\mythinspace;}
% \newunicodechar{:}{\mythinspace:}
\fi
\begin{document}
\ifx\HCode\undefined \else
\Css{body{background-color:gainsboro;}}
\Css{.fine{
white-space:nowrap;
}
}
\Tag{TITLE+}{possibilities for unbreakable space inside « » in HTML}
\catcode\!=\active%
\catcode\:=\active%
\catcode\;=\active%
\def\insertthinspace#1{%
\def#1{\unskip\mythinspace\detokenize{#1}}%
}
\def~{\unskip\mythinspace\ignorespaces}%
\insertthinspace! \insertthinspace: \insertthinspace;
%unusable solution by @michal.h21
%\def\guillemotleft{\HCode{&laquo;&nbsp;}}
%\def\guillemotright{\unskip\HCode{&nbsp;&raquo;}}
\fi

; œ ; Œ ; É ; È ; Ê ; À ; Á ; Å ; Ç

%\euro{}
; \oe{} ; \OE{} ; \'{E} ; \{E} ; \^{E} ; \'{A} ; \{A} ; \AA{} ; \c{C}

ī \={\i}

My quotes with breakable spaces, once in a html:
« blabla ».

In lualatex, the french spaces for !, ;, : are set properly.
No need for a ~ as in ~!, ~; ~:.

\textemdash~my text in long dash~---\\
---~asdmy text in long dash~\textemdash

\~{n}ana un tilde \~{}.

\char\~

\end{document}


The result:

• I was thinking about trying to use your solution here to allow my code to insert multiple adjacent spaces because in tex4ht commands like \hphantom don't work, so I thought your redefinition of ~ might allow ~~~~ to produce several spaces manually. Is it by design that this doesn't work? Since this question came up readily from a google search, I thought this was the more appropriate place to expand this horizontal space issue than a new question. Thanks. – EngBIRD Dec 27 '15 at 17:59
• @EngBIRD it should work, I've just tried to add several ~ between some words, they produced several spaces – michal.h21 Dec 27 '15 at 19:00
• My apologies, this indeed works with a xhtml compile, but not html. – EngBIRD Dec 28 '15 at 4:43
• @EngBIRD that's strange, it works for me also for html, even when I compile the document just with htlatex without any parameters – michal.h21 Dec 28 '15 at 7:59
• Thanks for checking, time permitting, I will permutate a MWE for a new question with a set of compile options and cfg files and post a new question to determine where the inconsistency lies. For example, I have determined that inserting multiple and consecutive ~ doesn't work when ExplSyntax is On` (even though it is a valid/successful character to force space between words in this same environment). – EngBIRD Dec 28 '15 at 18:45