
如何在 mcode 中排版“x=A\b”,它代表 MATLAB 中的“矩陣除法”?這是一個 MWE:
\documentclass[12pt]{report}
\usepackage{amsthm,amsmath, amssymb, paralist, fancybox, listings, mathtools, verbatim, textcomp}
\usepackage{mcode}
\usepackage[unicode,pdfborder={0 0 0 0}, colorlinks=true, urlcolor=red, linkcolor=black]{hyperref}
\usepackage{float}
\usepackage[font=small,labelsep=none]{caption}
\lstset{language=Matlab}
\begin{document}
In MATLAB, it can be solved by executing the statement \mcode{x = A \ b}
\end{document}
答案1
你可以寫一些類似的東西
\mcode{x = A \\ b }
似乎更好的選擇是重新定義\mcode
如下:
\renewcommand{\mcode}{\lstinline[basicstyle=\lstbasicfont]}
然後它似乎工作正常。
對我來說,這個重新定義\mcode
\mcode{x = A \ b}
根據您的需求進行排版。
參數中的某些內容在到達\lstinline
命令之前正在處理。更新後的定義可以\lstinline
更有效地處理其論點。
基本上,mcode.sty
定義了以下內容
\newcommand{\mcode}[1]{\lstinline[basicstyle=\lstbasicfont]|#1|}
如果你只是嘗試類似的事情
\lstinline[basicstyle=lstbasicfont]|x=A\b|
然後你就得到結果了。 listings
正在做各種魔術,例如\verb
。透過定義包裝器指令,\mcode
並非所有字元代碼都會很快處理。
看\lstinline!與 \lstinline{Foo}了解新定義的命令如何處理之間的差異
\mcode|x=A \ b|
和
\mcode{x = A \ b}
答案2
考慮使用matlab-prettifier
包裹反而:
\documentclass[a4paper]{article}
\usepackage{matlab-prettifier}
% Define a one-character shorthand (") for inline code.
\lstMakeShortInline[style=Matlab-editor]"
\begin{document}
"x=A\b" represents ``matrix division'' in MATLAB.
\end{document}