Latex-workshop: \providecommand breaks mathjax preview

Created on 14 Nov 2019  路  4Comments  路  Source: James-Yu/LaTeX-Workshop

It seems that \providecommand pollutes the preview rendered by Mathjax. This is related to @carmo-lucas' comment in 856

Consider

\documentclass[11pt]{article}
\usepackage{amsmath,amsfontsamssymb}
\usepackage[utf8]{inputenc}
\usepackage{t1enc}

\providecommand{\E}{{\mathbb E}}
\newcommand{\cf}{{\mathcal F}}

\begin{document}
$X$
\end{document}

Then preview yields

Capture d鈥檈虂cran 2019-11-14 a虁 08 51 25

Replacing \providecommand by \newcommand yields the correct preview

Capture d鈥檈虂cran 2019-11-14 a虁 08 52 16

There are two ways to handle this

  1. Ignore \providecommand definitions
  2. Turn \providecommand definitions into \newcommand definitions when sending the preamble to mathjax

Any comments?

bug

Most helpful comment

Hmm. This is a tricky one. Personally I think the benefits from turning \providecommand into \newcommand outweigh the drawbacks.

All 4 comments

Hmm. This is a tricky one. Personally I think the benefits from turning \providecommand into \newcommand outweigh the drawbacks.

I'm using someone else's .sty file so turning \providecommand to \newcommand could be problematic.

I fixed it by setting "latex-workshop.hover.preview.newcommand.parseTeXFile.enabled" to false.
Not a perfect solution but it works for what I need.

I was perhaps not clear. The translation from \providecommand to \newcommand would be achieved on the fly by the extension. In no way, would the .tex or any other included files be modified.

For reference: \providecommand acts as \newcommand but only creates a new alias if the alias doesn't already exist. So we should be able to achieve the same behaviour by simply passing all the providecommand's to MathJax first (as newcommand's). That way if there was a newcommand before the providecommand it will be the newcommand's definition that is used.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BjoernDaase picture BjoernDaase  路  3Comments

domenicozambella picture domenicozambella  路  4Comments

fsonntag picture fsonntag  路  4Comments

TiemenSch picture TiemenSch  路  6Comments

LordScree picture LordScree  路  5Comments