yzane / vscode-markdown-pdf

Markdown converter for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=yzane.markdown-pdf
Other
1.01k stars 206 forks source link

Markdown + pdf and LaTeX Equation #322

Open amirtadayon opened 1 year ago

amirtadayon commented 1 year ago

When insert a LaTeX expression in the Markdown document and export it into a PDF file, those expressions are not shown nicely. Here is an example

image

However, when previewing it on VSCode, it looks fine.

image

Any suggestion, workaround is very much appreciated.

Thanks

GitHubonline1396529 commented 1 year ago

Hello,

This is not a perfect solution, but maybe this can help :

edit the file (on Windows) :

C:/Users/<username>/.vscode/extensions/yzane.markdown-pdf-<version>/template/template.html

replace <username> and <version> with your own username on your PC and version of your markdown-pdf

append these two lines to the end of the file :


<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: {inlineMath: [['$', '$']]}, messageStyle: "none" });</script>

then try Export (pdf) again...

AnyaReese commented 1 year ago

same solution, it also works on mac with path

/Users/<username>/.vscode/extensions/yzane.markdown-pdf-<version>/template/template.html

or just append these lines to your markdown file

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({ tex2jax: {inlineMath: [['$', '$']]}, messageStyle: "none" });
</script>
boyforsky commented 1 year ago

你好,

这不是一个完美的解决方案,但也许这可以帮助:

编辑文件(在 Windows 上):

C:/Users/<username>/.vscode/extensions/yzane.markdown-pdf-<version>/template/template.html

<username>和替换<version>为您在 PC 上的用户名和版本markdown-pdf

将这两行附加到文件末尾:

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: {inlineMath: [['$', '$']]}, messageStyle: "none" });</script>

然后再试Export (pdf)一次...

这种方法无法应对多行latex公式

boyforsky commented 1 year ago

same solution, it also works on mac with path

/Users/<username>/.vscode/extensions/yzane.markdown-pdf-<version>/template/template.html

or just append these lines to your markdown file

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({ tex2jax: {inlineMath: [['$', '$']]}, messageStyle: "none" });
</script>

This method cannot cope with multi-line latex formulas

Redhead-San commented 7 months ago

I found a solid workaround, works fine for me. First, add displayMath: [ ['$$','$$'], ["\\[","\\]"] ] to above mentioned file. Then, as the extension treats every \ as an escaping char, add two of them for every occurrence of the backslash char \

So your e.g. parentheses matrix has to look like this:

$$\begin{pmatrix}
1 & 2 & 3 \\\\
4 & 5 & 6
\end{pmatrix}$$

Final html code to everyones convenience:

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({ tex2jax: {inlineMath: [['$', '$']], displayMath: [ ['$$','$$'], ["\\[","\\]"] ]}, messageStyle: "none" });
</script>