2

After resolving the hyperref issues with tex4ht, I'm still having issues with the math rendering. The following MWE compiles fine with pdflatex, except for the d operator:

\documentclass[a4paper, 12pt, ngerman]{scrartcl}

\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenx}
\usepackage{lmodern}

\usepackage[a4paper, left=30mm, right=25mm, top=25mm, bottom=30mm]{geometry}
\usepackage{setspace}
\onehalfspacing
\parindent0mm

\usepackage{amsmath}
\usepackage{commath}
\usepackage{units}
\renewcommand{\dpd}[3][]{\ensuremath{\mathinner{%
      \dfrac{\partial{{}^{#1}}#2}{\partial{{#3}^{#1}}}
}}}
\renewcommand\dif{\mathop{d}\!}

\usepackage[breaklinks, colorlinks]{hyperref}

\begin{document}

Erstmal etwas inline-Mathe $E = m c^2$, etwas sinnloser Text und dann eine lange, abgesetzte Formel:
\begin{multline}
\iiint_V \dpd{E}{t} \dif V + \iint_S E u_i n_i \dif S = \\
\iint_S \tau_{ij} u_i n_j \dif S - \iiint_V \dpd{p u_i}{x_i} \dif V + 
\iiint_V \rho f_i u_i \dif V - \iint_S q_i n_i \dif S \label{eq:energie}
\end{multline}

\autoref{eq:energie} ist ein gutes Beispiel für eine lange und komplizierte Gleichung, die nicht mehr auf eine Zeile passt.

\end{document}

With the new definition for d, I noticed it is not upright anymore and its baseline is not properly aligned in the PDF! Wrong d In the HTML: When I set the math renderer to MathML, the integrals look better, although the superfluous space between d and the corresponding variable persists. MathML improved rendering But it still does not look as nice as if I insert the same LaTeX source code on this page: MathJax with wrong d Except that d is not upright, everything else looks good. So why do I get two different math renderings from the same LaTeX source code? Is this just a CSS issue? Just to make this clear: d should be put upright, and the reason I am using the redefined \dif macro is:

The changes are mainly the code needed for Tikz externalization, but there are also fixes for commands provided by Commath package:

\renewcommand{\dpd}[3][]{\ensuremath{\mathinner{%
      \dfrac{\partial{{}^{#1}}#2}{\partial{{#3}^{#1}}}
}}}
\renewcommand\dif[1]{\mathop{#1}\!}

The original ones produced wrong Mathml code, because there were missing or incorrect bases for superscripts or spacing commands inside the math operator. This package is quite a long time without updates, I guess that there will be issues also with other commands it provides.

Otherwise put: What is the best way to ensure my formulae written in LaTeX will look as good in HTML as they do in the PDF?

winkmal
  • 845
  • It would seem that \mathop automatically centers its argument about the math-axis, accounting for the vertical shift. Also, \mathop{d} will set the d in italic. – Steven B. Segletes Jan 13 '17 at 15:31
  • Is there a spacing problem with just using \renewcommand\dif{\mathrm{d}}, if the goal is an upright d? – Steven B. Segletes Jan 13 '17 at 15:40
  • use \DeclareMathOperator from amsmath to declare d with the correct horizontal spacing and without vertical centering – David Carlisle Jan 13 '17 at 15:46
  • 1
    there is no reason to suppose that the mathjax and latex renderings are the same, typically they are using different fonts and the typesetting engines are using completely different technologies and have no code in common. – David Carlisle Jan 13 '17 at 15:48
  • @DavidCarlisle, could you please elaborate? Because if I use \DeclareMathOperator{\dif}{d\!} instead of \renewcommand{...}, it gives the following error: ! LaTeX Error: Command \dif already defined. – winkmal Jan 13 '17 at 16:21
  • That is because it is already defined. Actually it is defined to be a math operator d pretty much as you have it already but without the spacing problems so best would be simply remove the \renewcommand – David Carlisle Jan 13 '17 at 16:29
  • @StevenB.Segletes, \renewcommand\dif{\mathrm{d}} works fine for the PDF. In the HTML, when changing the math renderer to MathML, I notice a space between the d and the following variable, which is not present in the PDF, neither with the original math renderer (HTML-CSS), which however produces ugly integrals. @DavidCarlisle, this was my original setting, but then d would not show up in the HTML at all, as you can see here. – winkmal Jan 13 '17 at 16:31
  • Argggggg I wondered why you had that weird \mathinner use. I should have guessed commath I'm sorry but there is no other way to say this. don't use that package, almost every line of its code exhibits one or more incorrect use of tex commands. – David Carlisle Jan 13 '17 at 16:42
  • So the problem is commath!? How about an update? I still find it more convenient to write \dpd{E}{t} than \dfrac{\partial E}{\partial t}. On the other hand, MediaWiki syntax also uses latex syntax inside of <math> tags, like here, and they get a very decent math rendering, although it seems they just convert it to SVG images. I know that tex4ht can be configured thus. Could someone please post answer, or should I answer my own question summarizing the comments? To get it closed. – winkmal Jan 17 '17 at 09:13

0 Answers0