Search code examples
pdfvisual-studio-codemarkdown

How to export markdown to pdf with math matrix


I know that in vs code, markdownpdf extension can export md into pdf, but this extension is unable to convert latex correctly. A common way is to add the code below at the beginning of the md.

<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 partly solve the problem. But it still can not correctly convert those environment which includes "\\" grammar like array, eqnarray. So those equations with matrix can not be converted correctly.

I would like to ask how to solve this problem.


Solution

  • One partial solution I found is to install the Markdown Converter extension by manuth. This extension can convert math matrices to PDF but unfortunately does not support eqnarray.

    Here's a sample markdown:

    ---
    Author: "Bunny Red"
    ---
    
    # This is a test
    Inline equations $1+1=2$ work.
    
    Matrices also work:
    $$
    \begin{vmatrix}
      a_1 & b\\
      c_1 & d
    \end{vmatrix}+\begin{vmatrix}
      a_2 & b\\
      c_2 & d
    \end{vmatrix}=\begin{vmatrix}
      a_1+a_2 & b\\
      c_1+c_2 & d
    \end{vmatrix}
    $$
    
    $$
    \begin{bmatrix}
      1 & 1 & 1 \\
      1 &-1 & 0 \\ 1 & 1 & 1 
    \end{bmatrix} \xrightarrow{R_3-R_2,\ R_2-R_1}\begin{bmatrix}
      1 & 1 & 1 \\
      0 &-2 & -1 \\ 0 & 2 & 1 
    \end{bmatrix} \xrightarrow{R_2+R_3}\begin{bmatrix}
      1 & 1 & 1 \\
      0 &-2 & -1 \\ 0 & 0 & 0 
    \end{bmatrix} 
    $$
    
    `pmatrix` does not look great: $\text{Find inverse of }\begin{pmatrix}3 & -2 \\5 & -4 \\ \end{pmatrix}$
    
    Some emojis do not work : 😀✅❌
    

    Press CTRL + SHIFT + P and search and select Markdown: Convert Document to print markdown file to PDF.

    Here's a screenshot of the PDF: enter image description here