3

I want to create SVG diagrams for articles viewed on a site with MathJaX enabled. The diagrams are mainly created in PSTricks as follows.

\documentclass[pstricks,border=1cm,12pt,dvipsnames]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsfonts, amssymb}
\usepackage{pst-eucl}

\begin{document}
\begin{pspicture}[showgrid](6,6)
\pstTriangle[PointNameA=\alpha,PointNameB=\beta,PointNameC=\gamma](4,1){A}(1,3){B}(5,5){C}
\pstCircleABC[linecolor=blue]{A}{B}{C}{O}
\rput[c](3,2.5){$\angle x y z = 30^\circ$}
\end{pspicture}
\end{document} 

Once I compiled it with dvisvgm <filename> (file extension can be ignored) and feed it to an HTML page as follows,

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript" async
            src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML">
    </script>
</head>
<body>
    <p><img src="test.svg" /></p>
    <p>
        Angle \(\angle x y z\) and \(\alpha, \beta, \gamma\).
    </p>
</body>
</html>

I got disappointed result as follows.

enter image description here

Unfortunately, the font used by MathJax differs from ones used in my SVG diagrams.

Question

What LaTeX fonts are available for all browsers and devices on the earth and match the fonts used by MathJaX?

  • Looks like mathjax supports multiple fonts docs.mathjax.org/en/latest/font-support.html so I guess you could use whichever one of those you've set it up to use. – TH. Mar 21 '18 at 1:37
  • I think you should ask the bonus question as a separate question with a MWE. – TH. Mar 21 '18 at 1:38
3

I believe most of this information is available from the LaTeX Font Catalogue.

  • MathJax Tex. I'm not sure about
  • STIX

    \usepackage[T1]{fontenc}
    \usepackage{stix}
    
  • Asana Math

    \usepackage{fontspec}
    \setmainfont{Asana-Math}
    
  • Neo Euler. There are a number of fonts that use Euler math, but I don't know what Neo refers to here. New PX with Euler math maybe?
  • Gyre Pagella

    \usepackage{tgpagella}
    \usepackage[T1]{fontenc}
    
  • Gyre Termes

    \usepackage{tgtermes}
    \usepackage[T1]{fontenc}
    
  • Latin Modern

    \usepackage{lmodern}
    \usepackage[T1]{fontenc}
    

Presumably, you could install the actual OTF fonts from their repository and use them with fontspec and xelatex.

  • 1
    I wondered that myself. I don't know the answer and the only thing I ever recall seeing about it was this ancient page tex.loria.fr/ctan-doc/macros/latex/doc/html/fntguide/… which suggests loading fontenc after the font to prevent loading T1-encoded fonts from the cmr family. – TH. Mar 21 '18 at 2:32
  • I suspect your best bet is going to be installing the exact fonts they use and selecting the appropriate one. – TH. Mar 21 '18 at 2:35
  • To use Termes or Pagella for math, you should be loading newtxtext and newtxmath or newpxtext and newpxmath. Just loading tgpagella or tgtermes will only change the text font. – Corey Mar 21 '18 at 4:56
  • @Corey, you're correct that tgpagella and tgtermes just set the text font. But newpxtext and newtxtext appear to use different text fonts (perhaps the X variants are just extensions?). The math fonts seem to be constructed from a bunch of other fonts like URWPalladioL-Ital and zplx-regular. I guess I'm not sure what MathJax is doing precisely. – TH. Mar 21 '18 at 15:43
  • The comment I responded to about package ordering seems to have disappeared. I completely forgot that I asked about this years ago. tex.stackexchange.com/questions/2859/… – TH. Apr 5 '18 at 20:07
2

Here, it's displayed correctly, after I have correctly set the path to the GS lib in the dvisvgm command line option. See in particular this page: http://dvisvgm.bplaced.net/FAQ

For me, with Ghostscript installed by macports (on Mac), if I launch dvisvgm --libgs=/opt/local/bin/gs svg.dvi svg.svg I obtain this: enter image description here

Edit: with this MathJax setting: enter image description here

  • The dvisvgm binary from MacPorts does not need the --libgs option, contrarily to the TeXLive/MacTeX one. There is some discussion on TL2018 pretest on whether the TeXLive or MacTeX one could also find the libgs.dylib in /opt/local/lib automatically. (you can also set LD_LIBRARY_PATH in the environment). By the way are you sure your --libgs is correct. It should a priori refer to the dylib, not to gs binary. – user4686 Mar 21 '18 at 9:45
  • Without the --libgs option, the SVG obtained is missing some (Postscript?) parts of the graphic, on my installation. I have installed MacTeX 2017, but also other binaries tools not related to LaTeX via mac ports. which gs give me the path /opt/local/bin/gs. The lesson of my answer is that the problem is not related to fonts used in the .tex file, nor to the MathJax setting, but more likely to the dvisvgm usage. – quark67 Mar 21 '18 at 17:50
  • don't you have a ligbs.9.dylib in /opt/local/lib ? – user4686 Mar 21 '18 at 20:31
  • No, I don't have ligbs.9.dylib (probably a typo), but libgs.9.dylib on /opt/local/lib. But why this question? I don't have problem. By the way, I also found gs in /usr/local/bin (here gs is an alias to gs-noX11 executable). – quark67 Mar 22 '18 at 3:50
0

Quoted from the official site,

In order to avoid these problems, call dvisvgm with option -n or --no-fonts. It replaces the font elements by paths which are supported by nearly all SVG renderers.

enter image description here

With a note,

However, as there are no longer font characters present in the SVG file, the drawn text can’t be selected in the browser.

For me, it is not a big problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.