# Missing spaces between regular words

I noticed that sometimes tex4ht removes "regular" spaces between words. I understand that spaces in DVI is just a "gaps" not a font symbols. MWE:

\documentclass{article}
\usepackage{times}
\begin{document}
Normal text \texttt{In the Name} \texttt{of} \texttt{God}
\end{document}


Result in HTML compiled with htlatex without any options (there is no spaces in Name of God):

<!--l. 4--><p class="noindent" >Normal text <span
class="pcrr7t-">In the NameofGod</span>


Here's what I've found in tex4ht C code comments:

Characters are inserted into the html file as they are
encountered. Spaces are inserted when \'x_val' is larger than
\'max_x_val'.

static long int x_val = 0, max_x_val = -10000,


In the DVI file I see small space between words:

(Name)
w3 163840
(of)
w0
(God)


When I change in a DVI source w3 163840 to w3 263840 spaces shows up.

Question, is there a way to control tex4ht space conversion (from DVI to HTML)? Probably it's related some how with the fonts space character with?

And how can I trace down removed spaces? What this tracing horizontal spaces should show \special{t4ht@%X}...\special{t4ht@%x}. I didn't notice anything.

This is interesting. When you look at produced dvi codes for your example:

  xxx: 't4ht=<!--l. 9--><p class="noindent" >'
set: 'Nomal'
w: 2.500000pt
set: 'te'
right: -0.149902pt
set: 'xt'
w0:
fnt: pcrr7t at 10pt
set: 'In'
w: 6pt
set: 'the'
w0:
set: 'Name'
w: 2.500000pt
set: 'of'
w0:
set: 'God'


you can see that with of space is set to 2.5pt, because the normal width of interword space of the given line is used. It is not indicated that font was changed for the space, which is the problem.

tex4ht uses following calculation to determine whether space should be inserted:

i =  (INTEGER) (  (double) (dx = x_val - max_x_val)
/         (text_on? word_sp : margin_sp)
+         0.5 );


if I understand it correctly, x_val is current horizontal position of a new character, max_x_val is the last horizontal position before the space, so dx is width of the space. because we are in text (text_on), width of the space is divided by size of the font space. O.5 is added to it and then it is converted to integer.

when the result after converting to integer is 1, then space is inserted. the problem with your example is that while in reality spaces from proportional font were used, size of monospaced space was used in the calculation, resulting in value smaller than 1, so spaces aren't inserted. I am not sure whether this can be fixed in the tex4ht sources, from some code comments it seems that Eitan was aware of this problem, but didn't came with a solution. Good thing is that this issue should happen only when you use font with fixed spaces, which means monospaced, and insert normal spaces between two instances of text in this font.

• Nice answer michal.h21, one of crazy solutions I came up is to modify a TFM. I changed Courier pcrr7t.tfm (SPACE R 0.6) to the space from Times Roman (SPACE R 0.25) and all the missing spaces appeared. Would be nice that somebody could fix the source code. But from Eitans comment I see that its not so trivial to find a font switch for spaces. – Linuxss May 14 '15 at 6:52
• michal.h21, what tool do you use to expand DVI code? This code (from your post) looks more clear than dv2dt gives. – Linuxss May 14 '15 at 6:59
• @Linuxss I use dviasm. I think that modifications of tex4ht c sources are unlikely, because no one fully understand it yet. maybe if I learn c, it shouldn't be harder than TeX :) – michal.h21 May 14 '15 at 8:10

Here is a simple solution with \texttt configuration, where space is added like a HTML entity if there's a space after \texttt{}.

\documentclass{article}
\usepackage{times}
\begin{document}
\makeatletter
%% add fixed space if next input token is space
\ifcat\@@temp\space
\ \ignorespaces
\fi}

Now the output will be ... Name&#x00A0;of&#x00A0;God.