Kindly suggest latex to xml cfg code to get the following:

(1) LaTeX:




(2) LaTeX:

\Lambda \left(x\left| {y_{1},\ldots,y_{p}} \right.\right)=\frac{\Lambda 
(y_{1},\ldots,y_{p},x)} {\Lambda (y_{1},\ldots,y_{p} )},


<disp-formula id="s1234-E7">
<label alt="equation 7">(7)</label>
\Lambda \left(x\left| {y_{1},\ldots,y_{p}} \right.\right)=\frac{\Lambda 
(y_{1},\ldots,y_{p},x)} {\Lambda (y_{1},\ldots,y_{p} )},
  • If you use \verb| ... | in the LaTeX code then tex4ht will not change the contents in the HTML output. Jul 11, 2018 at 14:02

1 Answer 1


The following code is modified version of the mathjax-latex-4ht package. Save it as myaltmath.sty:

\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 }

% #1 math type, #2 math contents


The configurations which insert the required XML tags are saved in companion configuraton file, myaltmath.4ht:


% configure display math
% we want to save the math type info to an XML attribute, so we need to use three hooks


\Configure{DisplayMath}{\stepcounter{DisplayMathCount}\HCode{<disp-formula id="s1234-E\arabic{DisplayMathCount}" type="}}{\HCode{">\Hnewline
%<label alt="equation 7">(7)</label>

Important thing is that the \displayblockmath configuration inserts the type attribute, which can be then used for DOM manipulations. Because the LaTeX code is saved verbatim, it is not possible to add the <label> element from the TeX side, it must be done in the post-processing stage.

To require the myaltmath package, use the following configuration file:


The post-processing can be done using the LuaXML library in the make4ht build file (mybuild.mk4):

local domfilter = require "make4ht-domfilter"

local counters = {}
local function stepcounter(countertype)
  -- retrieve counter type value, or initialize a new one
  local currentval = counters[countertype] or 0
  local newval = currentval + 1
  counters[countertype] = newval
  return newval
local process = domfilter {
     -- process all equations and make label with their equation number
     for _, equation in ipairs(dom:query_selector("disp-formula")) do
       if equation:get_attribute("type") == "equation" then 
         local count = stepcounter("equation")
         local label = dom:create_element("label", {alt = "equation " .. count})
         label:add_child_node(label:create_text_node(string.format("(%i)", count)))
         equation:add_child_node(label, 1)
     return dom

-- replace the html$ with extension which you actually use, probably xml$
Make:match("html$", process)

Please note that I've found some bugs in LuaXML when I wrote this build file and it will take some time before the fixed version will be on CTAN. You can use the development version in the meantime.

To compile, use the following command

make4ht -uc myconfig.cfg -e mybuild.mk4 filename.tex

This is the result in HTML:

<!-- l. 6 --><p class='noindent'>Some text <inline-formula> 

</p><!-- l. 12 --><p class='indent'>   <disp-formula id='s1234-E1' type='equation'><label alt='equation 1'>(1)</label> 
\begin{equation} \label{eq7} \Lambda \left (x\left |{y_{1},\ldots ,y_{p}} \right .\right )=\frac{\Lambda (y_{1},\ldots ,y_{p},x)}{\Lambda (y_{1},\ldots ,y_{p} )}, \end{equation} 


As you can see, the white space is a bit messed up in the TeX code, this is a consequence of the \detokenize command. I am not sure that it can be fixed.

  • we are getting the following error message Output dir: Compiler: latex Latex options: -jobname=math tex4ht.sty : myconfig.cfg,,charset=utf-8 tex4ht -cmozhtf -utf8 build_file mybuild.mk4 Using build file mybuild.mk4 [string "local domfilter = require "make4ht-domfilter"..."]:1: module 'make4ht-domfilter' not found: no field package.preload['make4ht-domfilter'] [kpse lua searcher] file not found: 'make4ht-domfilter' [kpse C searcher] file not found: 'make4ht-domfilter' /usr/share/texlive/texmf-dist/scripts/make4ht/mkutils.lua:290: assertion failed! Jul 13, 2018 at 5:07
  • @Purushothaman which TeX distribution do you use? It seems that it contains older version of make4ht. It is best to use TL 2018. You may also try to install the development version of make4ht.
    – michal.h21
    Jul 13, 2018 at 7:48
  • 1
    We are using TeXLive 2015, ubuntu 16.04. We have updated the latest make4ht from the github. .../texmf/scripts/lua/make4ht/filters/make4ht-domfilter.lua:2: module 'luaxml-domobject' not found: no field package.preload['luaxml-domobject'] [kpse lua searcher] file not found: 'luaxml-domobject' [kpse C searcher] file not found: 'luaxml-domobject' /home/threetwo/texmf/scripts/lua/make4ht/mkutils.lua:413: assertion failed! Jul 14, 2018 at 5:20
  • @Purushothaman TL 2015 is really old, many things will be broken. The particular error message you got means that you need to update also LuaXML. But as I said, you may have a better luck with updated TL.
    – michal.h21
    Jul 14, 2018 at 7:41
  • DOM parsing of math.html failed: ...ive/2018/texmf-dist/tex/luatex/luaxml/luaxml-mod-xml.lua:174: Unbalanced Tag (/tex-math) [char=457] parse_lg process file: math.html outdir: parse_lg process file: math.css outdir: parse_lg process file: math.tmp tmp file Jul 17, 2018 at 6:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .