如何在 MikTeX 和 Windows 7 下使用 minted?

如何在 MikTeX 和 Windows 7 下使用 minted?

根據minted文件:

Windows 支援目前還很粗略/未經測試。有兩個複雜之處:安裝和使用......

這個問題尋求一步一步的闡述

如何minted在 Windows 下設定使用 MikTeX?

答案1

minted使用Pythonpygments庫,所以你需要:

  • 安裝Python,選擇你喜歡的版本:x64或者x86,最好選擇2.7.5版本。
  • Python添加PATH
    • 按住Win並按下Pause
    • 點選Advanced System Settings
    • 點選Environment Variables
    • 附加;C:\Python27PATH變數。
  • 安裝python-pip
  • 加到;C:\Python27\Scripts變數PATH
  • pip install pygments安裝Pygments(如果您已安裝,則應指定Perl完整路徑,因為還有一個同名的二進位)。pipPerl

  • 啟用-shell-escape選項進行編譯:

    \documentclass{article}
    \usepackage{minted}
    
    \begin{document}
        \begin{minted}[mathescape,
                       linenos,
                       numbersep=5pt,
                       gobble=2,
                       frame=lines,
                       framesep=2mm]{csharp}
          string title = "This is a Unicode π in the sky"
          /*
          Defined as $\pi=\lim_{n\to\infty}\frac{P_n}{d}$ where $P$ is the perimeter
          of an $n$-sided regular polygon circumscribing a
          circle of diameter $d$.
          */
          const double pi = 3.1415926535
        \end{minted}
    \end{document}
    

結果應該如下圖所示:

結果

答案2

安裝Python對於窗戶。然後安裝設定工具。這應該在您的目錄資料夾中添加easy_install.exe檔案(例如: 在我的電腦中。對您來說可能會有所不同。)ScriptspythonC:\Python26\Scripts\C:\Python26\Scripts使用使用者變數新增至您的系統路徑。您可能希望使用使用者友好的編輯器:路徑編輯器以此目的。

現在打開互聯網,轉到命令提示字元並輸入easy_install pygments

在此輸入影像描述

現在您可能需要重新啟動電腦。就這樣吧。嘗試這個測試檔案:

\documentclass{article}

\usepackage{amsmath}
\usepackage{minted} % loads fancyvrb

\newenvironment{eqnexample}
 {\VerbatimOut{\jobname.tmp}}
 {\endVerbatimOut
  \inputminted{latex}{\jobname.tmp}
  \input{\jobname.tmp}}

\begin{document}

\begin{eqnexample}
\begin{align}
  d &= \sqrt{ (x'-x)^2 }
  \\
  e &= 0
\end{align}
\end{eqnexample}

\begin{eqnexample}
\begin{multline}
  d = \sqrt{ (x'-x)^2 }  \\
  = f(x,x')
\end{multline}
\end{eqnexample}

\end{document}

在此輸入影像描述

相關內容