1

I am using the tex4ht config file here to leave math unchanged. However, I am getting a spurious space after commands such as \text{A} which get compiled as \text {A}. How to get rid of such spaces? Here's a MWE:

.tex

%Minimal example about extra spurious space

\documentclass[12pt]{article}
\usepackage[latin9]{inputenc}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{hyperref}
\usepackage[english]{babel}

\begin{document}

Next, some weird font stuff: $\mathbb{A}$, $\mathrm{A}$, $\text{A}$.
\end{document}

.cfg

\Preamble{xhtml,-css,NoFonts}

\newtoks\eqtoks 
\def\AltMath#1${\eqtoks{$#1$}% 
   \HCode{\the\eqtoks}$}
\Configure{$}{}{}{\expandafter\AltMath}  

\begin{document} 

\EndPreamble

output:

<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd-->
<html xmlns="http://www.w3.org/1999/xhtml"
>
<head>
   <title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" />
<meta name="originator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" />
<!-- html,xhtml,-css,NoFonts -->
<meta name="src" content="test.tex" />
<meta name="date" content="2018-05-01 11:27:00" />
</head><body
>
<!--l. 11--><p class="noindent" >Next, some weird font stuff: $\mathbb {A}$, $\mathrm {A}$, $\text {A}$. </p>
</body></html>
Manu
  • 493

1 Answers1

2

The spaces are inserted by TeX itself, so it is not so easy to get rid of them. We can use the l3regex package to remove spaces before left brackets.

\RequirePackage{l3regex}
\Preamble{xhtml,-css,NoFonts}

\newtoks\eqtoks 
\ExplSyntaxOn
\cs_new_protected:Npn \alteqtoks #1
{
  \tl_set:Nx \l_tmpa_tl {\detokenize{#1}}
  % delete spaces before left brackets
  \regex_replace_all:nnN { \x{20} \x{7B} } { \x{7B} } \l_tmpa_tl
  \tl_set:Nx \l_tmpb_tl{ \l_tmpa_tl }
  \HCode{\l_tmpb_tl}
}

\ExplSyntaxOff
\def\AltMath#1${\alteqtoks{$#1$}$}% 
% \def\AltMath#1${\eqtoks{$#1$}% 
% \HCode{\the\eqtoks}$}
\Configure{$}{}{}{\expandafter\AltMath}  

\begin{document} 

\EndPreamble

It uses the l3regex package to remove the spurious spaces before brackets. It produces the following result:

<body 
>
<!--l. 13--><p class="noindent" >Next, some weird font stuff: $\mathbb{A}$, $\mathrm{A}$, $\text{A}$. $a = b + c$ </p> 
</body> 
michal.h21
  • 50,697