
我正在嘗試為程式語言排版小步語義。我的計劃是使用 mathpartir 套件來編寫推理規則,並使用清單套件來排版語言片段。
如果我在常規數學環境中一起使用這兩個包,一切似乎都正常,如下圖第一個範例所示。但是,如果我嘗試使用 mathpartir 中的 mathpar 環境,那麼結果錯誤地向右移動,如第二個範例所示。
mathpartir 環境非常方便,因為它透過在每行上放置盡可能多的公式來自動組織公式。是否有一些解決方法可以使列表模組與 mathpar 一起工作?如果不是,至少有一種方法可以找出結果看起來錯誤的原因嗎?如果這是軟體包中的錯誤,我不知道應該歸咎於哪個軟體包。
微量元素
\documentclass{article}
\usepackage{mathpartir}
\usepackage{listings}
\lstset{
% without this the \hbox is not strictly necessary
basicstyle={\ttfamily},
}
\begin{document}
% Works fine:
\[
\infer{A \hbox{\lstinline!a!} A}{B \hbox{\lstinline!a!} B}
\]
% Weird shift:
\begin{mathpar}
\infer{A \hbox{\lstinline!a!} A}{B \hbox{\lstinline!a!} B}
\end{mathpar}
\end{document}
答案1
我沒有追蹤所有內容,但像往常一樣,在這種情況下,它有助於首先在框中設定有問題的程式碼
\documentclass{article}
\usepackage{mathpartir}
\usepackage{listings}
\lstset{
% without this the \hbox is not strictly necessary
basicstyle={\ttfamily},
}
\begin{document}
% Works fine:
\[
\infer{A \hbox{\lstinline!a!} A}{B \hbox{\lstinline!a!} B}
\]
% Weird shift:
\newbox\bA
\setbox\bA\hbox{\lstinline!a!}
\begin{mathpar}
\infer{A \usebox\bA{} B}{A \usebox\bA{} B}
\end{mathpar}
\end{document}
實際上,如果在本地恢復\par
到清單期望的值就足夠了(重置不會撤消,因此只能在群組中使用,如此處):
\documentclass{article}
\usepackage{mathpartir}
\usepackage{listings}
\lstset{
% without this the \hbox is not strictly necessary
basicstyle={\ttfamily},
}
\begin{document}
% Works fine:
\[
\infer{A \hbox{\lstinline!a!} A}{B \hbox{\lstinline!a!} B}
\]
% Weird shift:
\newcommand\zlstinline{\let\par\endgraf\lstinline}
\begin{mathpar}
\infer{A \hbox{\zlstinline!a!} B}{A \hbox{\zlstinline!a!} B}
\end{mathpar}
\end{document}