# Removing spaces before command

When using French guillemets with TeX4HT, the resulting symbols are not followed/preceded by non-breaking spaces like they should, resulting in wrong line-breaking in HTML.

I tried resetting \og and \fg with a babel.4ht file, but I can't get anything working. The only solution I've found so far is the following:

I defined new \Og and \Fg commands with:

\ifluatex
\newcommand{\Og}{\og}
\newcommand{\Fg}{\fg{}}
\else
\newcommand{\Og}{\HCode{&laquo;&nbsp;}}
\newcommand{\Fg}{\HCode{&nbsp;&raquo;}}
\fi


together with a sed hack to remove the spaces before &nbsp;:

sed -i "s@ *&nbsp; *@\&nbsp;@g" \$HTML


I'd like to get rid of this and do it properly in a .4ht file. How could I do this?

Edit:

The \Og/\Fg hack is actually acceptable for me, but not the sed one, so I'm modifying the title of this question: How can I remove spaces before the command?

-
I don't know TeX4HT (or even HTML for that matter), so I don't know if this comment is relevant, but the stringstrings package can do things like extract substrings, remove leading spaces, etc. You shuld be able to crop strings with it. –  Steven B. Segletes Feb 22 '13 at 14:26
Thanks for the pointer. \removeleadingspaces from the stringstrings package allows to remove leading spaces indeed. However, it doesn't remove the spaces from the string before the \Fg call… –  ℝaphink Feb 25 '13 at 13:03
I am trying to understand a concrete example of your need, but am having a hard time, because I am not fluent in your 4ht and html. I wrote stringstrings, so I have an interest in making it work for your need. Can you rephrase the problem with a MWE or in a more LaTeX'ey syntax? –  Steven B. Segletes Feb 26 '13 at 1:56
Are there any news here? –  Johannes_B May 12 at 20:42

You can use just \unskip to remove that unwanted space before &nbsp;:

\documentclass{article}

\usepackage[frenchb]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\begin{document}
some text \og and more text \fg\ and again some text
\end{document}


you can redefine \og and \fg either in the custom config file or in frenchb.4ht:

hello.cfg:

\Preamble{xhtml}
\AtBeginDocument{
\def\og{\HCode{&laquo;&nbsp;}}
\def\fg{\unskip\HCode{&nbsp;&raquo;}}
}
\begin{document}
\EndPreamble


compile with

htlatex filename "hello,charset=utf-8" " -cunihtf -utf8"


the result:

<p class="noindent" >some text &laquo;&nbsp;and more text&nbsp;&raquo; and again some text
</p>

-