
私はプログラミング言語のスモールステップセマンティクスをタイプセットしようとしています。私の計画は、推論ルールを記述するために mathpartir パッケージを使用し、言語フラグメントをタイプセットするために listing パッケージを使用することでした。
通常の数学環境で2つのパッケージを一緒に使用すると、次の画像の最初の例に示すように、すべて正常に動作するようです。ただし、mathpartirのmathpar環境を使用しようとすると、結果が誤って右にシフトされる2 番目の例に示すように。
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}