michal-h21 / make4ht

Build system for tex4ht
131 stars 15 forks source link

MATHML and sin(...) or cos(...) #109

Closed danielezambelli closed 9 months ago

danielezambelli commented 1 year ago

Hi Michal, I have found some errors when compiling in MATHML that do not appear when compiling in pdf or MATHJAX.

The compile command is: make4ht sincosdiv.tex -f html5-common_domfilters -c ml_make4ht -l -u -s -d ./html/mathml "mathml, 3, sec-filename, fn-in, blind"

The problem arises when the macro \sin (or \cos) is followed by a parenthesis.

Second problem is the \div symbol is rendered differently when I compile in MATHML.

P.S. I do not understand these warnings and how to fix them.

[WARNING] tocid: char-def module not found [WARNING] tocid: cannot fix section id's

The source:

\documentclass[10pt,a4paper,openright]{memoir}

\RequirePackage{amsmath, amssymb, amsthm}% amsfonts è caricato da amssymb
\RequirePackage[e]{esvect} % per i vettori
\RequirePackage{physics}   % fisica e differenziale (dd)
\RequirePackage{cancel} % per le semplificazioni
\RequirePackage[normalem]{ulem} % sottolineature
\RequirePackage[np,noaddmissingzero,autolanguage]{numprint}
\RequirePackage{mathtools} % da approfondire

\RequirePackage[greek, italian]{babel}
\usepackage{iftex}

\ifpdftex\typeout{************* PDFTeX*****************}
  \RequirePackage[T1]{fontenc}
  \RequirePackage[utf8]{inputenc}% non più necessario, ma non disturba
  \RequirePackage{stix2} % font

\else
  \ifluatex\typeout{************* LuaLaTeX *****************}
    \usepackage{fontspec}
    \setmainfont{STIX}[Ligatures=TeX]
    \usepackage[math-style=ISO]{unicode-math}
    \setmathfont{STIX Two Math}
  \fi
\fi

\RequirePackage{eurosym} % simbolo dell'euro
\RequirePackage{pifont} % simboli unicode
\RequirePackage[inline]{enumitem} % elenchi
\RequirePackage{multicol} % testo su più colonne
\RequirePackage{multirow} % tabelle con celle su più righe
\RequirePackage{quoting} % per le citazioni
\quotingsetup{font=small}
\RequirePackage{tabto} % per punti di tabulazione
\RequirePackage{microtype} % per la composizione fine
\RequirePackage[usenames, dvipsnames]{xcolor}   % gestione colori
\RequirePackage{pgfplots} % per axis
\RequirePackage{tikz}
\RequirePackage{tkz-fct} % per il disegno di funzioni
\RequirePackage{tikz-qtree} % per alberi
\usetikzlibrary{
  arrows,%
  arrows.meta,
  through,
  automata,%
  backgrounds,%
  calc,%
  circuits.ee.IEC,
  decorations.markings,%
  decorations.shapes,%
  decorations.text,%
  decorations.pathreplacing,%
  fit,%
  matrix,%
  mindmap,%
  patterns,%
  positioning,%
  intersections,%
  shapes,%
  shapes.geometric,
}
\RequirePackage{tkz-euclide} % in geometria viene usato \tkzDrawSegment

\RequirePackage[most]{tcolorbox}% per i box colorati
\RequirePackage{piton}% per i listati dei programmi
\PitonOptions{line-numbers, auto-gobble, background-color = green!15,
              splittable=3, break-lines-in-Piton, indent-broken-lines,
              }
\RequirePackage[colorlinks, hyperindex, pagebackref,
                linkcolor=RoyalBlue, filecolor=RoyalBlue,
                citecolor = black, urlcolor=RoyalBlue]{hyperref}
\RequirePackage{imakeidx}   % Indice analitico
\makeindex[options={-s matlibera.ist}, title=Indice analitico, intoc,
           columns=2]

% Insiemi numerici:
\newcommand{\R}{\mathbb{R}} % Reali
\newcommand{\IR}{{}^*\hspace{-.12em}\mathbb{R}} % Iperreali

\newcommand{\coloresem}{yellow}

\theoremstyle{plain}

\tcbset{
esemstyle/.style={
fonttitle=\bfseries\upshape, fontupper=\slshape,
arc=0mm, colback=\coloresem!5!white, colframe=\coloresem!50!black,
theorem style=plain, coltitle=\coloresem!30!black}
}

\newtcbtheorem[number within=chapter]{esempio}{Esempio}
              {esemstyle}{esem}

\newcommand{\tonda}[1]{\left( #1 \right)}

\begin{document}

\section{Error in sin(\dots) or cos(\dots)}
\begin{verbatim}
If: 
\(\sin x = a\)
then: 
\(\sin \tonda{x + \pi} = a\)

If: 
\(\cos x = a\)
then: 
\(\cos \tonda{x + 2\pi} = a\)
\end{verbatim}

If: 
\(\sin x = a\)
then: 
\(\sin \tonda{x + \pi} = a\)

If: 
\(\cos x = a\)
then: 
\(\cos \tonda{x + 2\pi} = a\)

It is okay so far.

\begin{verbatim}
If: 
\(\sin x = a\)
then: 
\(\sin (x + 2\pi) = a\)

If: 
\(\cos x = a\)
then: 
\(\cos (x + 2\pi) = a\)
\end{verbatim}

If: 
\(\sin x = a\)
then: 
\(\sin (x + 2\pi) = a\)      % Line giving error.

If: 
\(\cos x = a\)
then: 
\(\cos (x + 2\pi) = a\)      % Line giving error.

\begin{verbatim}
[ERROR]   htlatex: Compilation errors in the htlatex run
[ERROR]   htlatex: Filename     Line    Message
[ERROR]   htlatex: ./sincosdiv.tex      145      Extra }, or forgotten \right.
[ERROR]   htlatex: ./sincosdiv.tex      145      Missing } inserted.
[ERROR]   htlatex: ./sincosdiv.tex      150      Extra }, or forgotten \right.
[ERROR]   htlatex: ./sincosdiv.tex      150      Missing } inserted.
\end{verbatim}

\section{Symbol div rendered differently}

\begin{verbatim}
\(A \div B ~ \rightarrow ~ Q \text{ and } R 
  \qquad \text{ if } 
  Q \cdot B + R = A\)
\end{verbatim}

\(A \div B ~             % Symbol \div is rendered differently in MATHML.
  \rightarrow ~ Q \text{ and } R 
  \qquad \text{ if } 
  Q \cdot B + R = A\)

\end{document}

Thank you for your attention.

Daniele

michal-h21 commented 1 year ago

Hi Danielle, it seems to be caused by the physics package. I will take a look at it later, but both issues go away when I remove it. It seems that it redefines lot of math commands in a way which doesn't work with TeX4ht.

michal-h21 commented 1 year ago

It seems this file, physics.4ht should fix it:


\DeclareDocumentCommand\argopen{s}{} % Special open grouping for argument of a function
\DeclareDocumentCommand\argclose{s}{} % Special close grouping for argument of a function
\Hinput{physics}
\endinput

Regarding the \div command, it seems that physics redefines it to this symbol. I get the same result even in the PDF output. The original symbol is available as \divisionsymbol.

danielezambelli commented 1 year ago

I removed the "physics" package from my project.

Thank you.

michal-h21 commented 1 year ago

The fix didn't help?

danielezambelli commented 1 year ago

The fix works for sin(...) and cos(...) then I had other problems with tan(...) and preferred to directly implement the two commands I needed (\dd and \dx) without loading the whole package.

I do not know too much about LaTeX, and sometimes I find solutions that are not the best.

michal-h21 commented 1 year ago

In general, I think it is better to not load too many packages, as it increases the compilation time significantly, and it also can lead to clashes between command definitions. So it is best if you were able to create custom commands that work for you.