4

EDIT: @michal.h21

you tip works well, but if I use a numerical code such as   for thin space, instead of its name   in your modified trick,

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

then the make4ht outputs an error:

(d:/texlive/texmf-dist/tex/latex/newunicodechar/newunicodechar.sty)
! Illegal parameter number in definition of \mythinspace.
<to be read again>
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} ???

========= END OF EDIT ============

In my .tex, I use both --- and \textemdash and I put always a ~ inside my long dashes. Nonetheless, in the .html, the ~ are suppressed in being turned into a regular breakable space.

Is it possible to tell

I know nothing about html, but I want to output a .html, from a .tex which is written in utf8 and contains quotes «, » and other inputs like this that lualatex displays well in a .pdf. the problem is that, contrary to lualatex which makes unbreakable the spaces inside thequotes, my command

make4ht -ul hello.tex

does not put unbreakable space inside the «, ». @michal.h21, michal.h21, Removing spaces before command, gives a solution for replacing, in the .html, personal commands in the .tex but since I enter directly the quotes «, », I cannot use them.

For portability in order to avoid a .cfg, I also want a solution which can be put, in the .tex, inside the \ifx\HCode\undefined \else:

\ifx\HCode\undefined \else
%unusable solution by @michal.h21
%\def\guillemotleft{\HCode{&laquo;&nbsp;}}
%\def\guillemotright{\unskip\HCode{&nbsp;&raquo;}}
\fi

A complete document would thus be :

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

\ifx\HCode\undefined \else
\Css{body{background-color:gainsboro;}}
\Tag{TITLE+}{possibilities for unbreakable space inside « » in HTML}
%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 ~!, ~; ~:.





\end{document}

Here, is exposed various spaces in html:

The best way to create a fixed-width nonbreaking space in HTML is probably to use the no-break space and style its width. Since the width of an inline element cannot be set in CSS, according to the specifications, we make the element an inline block. This means markup like the following (where   can be replaced by the no-break space character itself:

<span class=fine>&nbsp;</span>

The style sheet could be:

.fine {
  display: inline-block;
  width: 0.125em;
} 

which gives

<div>text before the quote <a class=fine> </a>: «<a class=fine> </a>the quote itself <a class=fine> </a>!<a class=fine> </a>».</div>

He says that there is also a NARROW NO-BREAK SPACE, along with the ordinary NO-BREAK SPACE.

QUESTION:

How can I my «, » in my .tex be transformed, in the html, into

  • «<a class=fine> </a>
  • <a class=fine> </a>»

in general how can I be sure that the french spacing (for !, ;, : and so on) is used in my html ?

1

I think it is better to use a .cfg file, which is reusable, than modifying your source file. But you want it, so here it is:

\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\mythinspace{\HCode{<span class="fine"> </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;}
}
\Tag{TITLE+}{possibilities for unbreakable space inside « » in HTML}
\catcode`\!=\active%
\catcode`\:=\active%
\catcode`\;=\active%
\def\insertthinspace#1{%
  \def#1{\unskip\mythinspace\detokenize{#1}}%
}
\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 ~!, ~; ~:.
\end{document}

we use \newunicodechar for « and », for :, ! and ; we must use catcode to make them active. This way we can declare them as macros and insert any code we want.

We must use \unskip for removing previous spaces and \ignorespaces for following spaces, we would get two consecutive spaces otherwise.

The result:

enter image description here

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.