1

My Line Equations are:

$k'^4_{i}$

i'm expecting this

$k^{\prime 4}_{i}$

How to change ' to \prime and grouping all the things. How to do?

1
  • Again, ' symbol generally in superscript position, if you need to get anything in superscript along with ' symbol, for TeX compilation it works without this grouping, but TeX4ht purely works based on correct LaTeX coding, so obviously it won't work...
    – MadyYuvi
    Commented Oct 7, 2020 at 8:41

1 Answer 1

3

This depends on the way you use to display your math. Your example cannot work if you use methods that depend on correct LaTeX input to insert HTML or MathML tags. TeX4ht uses TeX expansion to insert tags, so it cannot analyze your source and try to guess your intentions. So the default method or MathML are out of the game.

You can use alternative methods though. One, which is not really recommended, is to use images for your math. This method has many flaws, the most important is that the images are not aligned to the baseline, so they may look bad in paragraphs.

Here is a MWE:

\documentclass{article}
\begin{document}
Here is the correct input: $k^{\prime 4}_{i}$. 
This is the original input: $k'^4_{i}$.
\end{document}

You can try to convert it to SVG images using:

make4ht sample.tex "pic-m,svg"

This is the result:

enter image description here

Another possibility is to keep your math input unconverted and let MathJax to convert it:

make4ht sample.tex "mathjax"

This is the result:

enter image description here

You can see that it looks much better. The downside is that it is harder to add support for custom commands, which I think you use.

You can also preprocess your input file using a script that will change your original input to the correct input and pass that to make4ht using pipe.

Here is such script, filter.lua:

for line in io.lines() do
  line = line:gsub("%'%^(.-)%_", "^{\\prime %1}_")
  print(line)
end

It uses simple regular expression to change your input to the correct input. You can use it with make4ht using the following command:

texlua filter.lua < sample.tex | make4ht -j sample - "mathml,mathjax"

The -j option is used to name the output file, which is necessary because the input comes from a pipe. The dash used in the place of filename tells make4ht to read input from the standard input.

We use MathJax do render MathML, as MathML is not supported by all browsers. This method works for custom commands, so it is probably best for your use case.

Here is the result:

enter image description here

You can see that is is the same as

You must log in to answer this question.

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