我想在 LaTex 中为 Coq 代码添加一个不错的语法高亮。有谁知道.sty
通常使用哪个包或什么程序来实现这个功能?我试过了铸造并获得了对于 Coq 来说太过通用的语法高亮:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{minted}
\usemintedstyle{tango}
\begin{document}
\begin{minted}{coq}
Module Type types.
Parameter P PI: Type.
End types.
\end{minted}
\end{document}
答案1
我知道这个问题最初是针对 minted 提出的,但让我分享一个显然是由阿西亚·马哈布比并由以下人员分享(和调整?)尼克·吉安纳拉基斯。
下列:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{xcolor}
\usepackage{listings}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{ltblue}{rgb}{0,0.4,0.4}
\definecolor{dkviolet}{rgb}{0.3,0,0.5}
% lstlisting coq style (inspired from a file of Assia Mahboubi)
\lstdefinelanguage{Coq}{
% Anything betweeen $ becomes LaTeX math mode
mathescape=true,
% Comments may or not include Latex commands
texcl=false,
% Vernacular commands
morekeywords=[1]{Section, Module, End, Require, Import, Export,
Variable, Variables, Parameter, Parameters, Axiom, Hypothesis,
Hypotheses, Notation, Local, Tactic, Reserved, Scope, Open, Close,
Bind, Delimit, Definition, Let, Ltac, Fixpoint, CoFixpoint, Add,
Morphism, Relation, Implicit, Arguments, Unset, Contextual,
Strict, Prenex, Implicits, Inductive, CoInductive, Record,
Structure, Canonical, Coercion, Context, Class, Global, Instance,
Program, Infix, Theorem, Lemma, Corollary, Proposition, Fact,
Remark, Example, Proof, Goal, Save, Qed, Defined, Hint, Resolve,
Rewrite, View, Search, Show, Print, Printing, All, Eval, Check,
Projections, inside, outside, Def},
% Gallina
morekeywords=[2]{forall, exists, exists2, fun, fix, cofix, struct,
match, with, end, as, in, return, let, if, is, then, else, for, of,
nosimpl, when},
% Sorts
morekeywords=[3]{Type, Prop, Set, true, false, option},
% Various tactics, some are std Coq subsumed by ssr, for the manual purpose
morekeywords=[4]{pose, set, move, case, elim, apply, clear, hnf,
intro, intros, generalize, rename, pattern, after, destruct,
induction, using, refine, inversion, injection, rewrite, congr,
unlock, compute, ring, field, fourier, replace, fold, unfold,
change, cutrewrite, simpl, have, suff, wlog, suffices, without,
loss, nat_norm, assert, cut, trivial, revert, bool_congr, nat_congr,
symmetry, transitivity, auto, split, left, right, autorewrite},
% Terminators
morekeywords=[5]{by, done, exact, reflexivity, tauto, romega, omega,
assumption, solve, contradiction, discriminate},
% Control
morekeywords=[6]{do, last, first, try, idtac, repeat},
% Comments delimiters, we do turn this off for the manual
morecomment=[s]{(*}{*)},
% Spaces are not displayed as a special character
showstringspaces=false,
% String delimiters
morestring=[b]",
morestring=[d]’,
% Size of tabulations
tabsize=3,
% Enables ASCII chars 128 to 255
extendedchars=false,
% Case sensitivity
sensitive=true,
% Automatic breaking of long lines
breaklines=false,
% Default style fors listings
basicstyle=\small,
% Position of captions is bottom
captionpos=b,
% flexible columns
columns=[l]flexible,
% Style for (listings') identifiers
identifierstyle={\ttfamily\color{black}},
% Style for declaration keywords
keywordstyle=[1]{\ttfamily\color{dkviolet}},
% Style for gallina keywords
keywordstyle=[2]{\ttfamily\color{dkgreen}},
% Style for sorts keywords
keywordstyle=[3]{\ttfamily\color{ltblue}},
% Style for tactics keywords
keywordstyle=[4]{\ttfamily\color{dkblue}},
% Style for terminators keywords
keywordstyle=[5]{\ttfamily\color{dkred}},
%Style for iterators
%keywordstyle=[6]{\ttfamily\color{dkpink}},
% Style for strings
stringstyle=\ttfamily,
% Style for comments
commentstyle={\ttfamily\color{dkgreen}},
%moredelim=**[is][\ttfamily\color{red}]{/&}{&/},
literate=
{\\forall}{{\color{dkgreen}{$\forall\;$}}}1
{\\exists}{{$\exists\;$}}1
{<-}{{$\leftarrow\;$}}1
{=>}{{$\Rightarrow\;$}}1
{==}{{\code{==}\;}}1
{==>}{{\code{==>}\;}}1
% {:>}{{\code{:>}\;}}1
{->}{{$\rightarrow\;$}}1
{<->}{{$\leftrightarrow\;$}}1
{<==}{{$\leq\;$}}1
{\#}{{$^\star$}}1
{\\o}{{$\circ\;$}}1
{\@}{{$\cdot$}}1
{\/\\}{{$\wedge\;$}}1
{\\\/}{{$\vee\;$}}1
{++}{{\code{++}}}1
{~}{{$\sim$}}1
{\@\@}{{$@$}}1
{\\mapsto}{{$\mapsto\;$}}1
{\\hline}{{\rule{\linewidth}{0.5pt}}}1
%
}[keywords,comments,strings]
\begin{document}
\begin{lstlisting}[language=Coq]
Module Type types.
Parameter P PI: Type.
End types.
\end{lstlisting}
Hello World in Coq, courtesy of http://coq-blog.clarus.me/tutorial-a-hello-world-in-coq.html.
\begin{lstlisting}[language=Coq]
Require Import Coq.Lists.List.
Require Import Io.All.
Require Import Io.System.All.
Require Import ListString.All.
Import ListNotations.
Import C.Notations.
(** The classic Hello World program. *)
Definition hello_world (argv : list LString.t) : C.t System.effect unit :=
System.log (LString.s "Hello world!").
\end{lstlisting}
Inductive definition, courtesy of https://coq.inria.fr/a-short-introduction-to-coq.
\begin{lstlisting}[language=Coq]
Inductive even : N -> Prop :=
| even_0 : even 0
| even_S n : odd n -> even (n + 1)
with odd : N -> Prop :=
| odd_S n : even n -> odd (n + 1).
\end{lstlisting}
\end{document}
给出以下内容(我认为并不完全令人满意):
在我看来,minted 实际上做得更好,如下所示
% !TeX document-id = {34714a8d-170f-4947-a4b9-b8812e4a094a}
% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{minted}
\usemintedstyle{tango}
\begin{document}
\begin{minted}{coq}
Module Type types.
Parameter P PI: Type.
End types.
\end{minted}
\begin{minted}{coq}
Require Import Coq.Lists.List.
Require Import Io.All.
Require Import Io.System.All.
Require Import ListString.All.
Import ListNotations.
Import C.Notations.
(** The classic Hello World program. *)
Definition hello_world (argv : list LString.t) : C.t System.effect unit :=
System.log (LString.s "Hello world!").
\end{minted}
Inductive definition, courtesy of https://coq.inria.fr/a-short-introduction-to-coq.
\begin{minted}{coq}
Inductive even : N -> Prop :=
| even_0 : even 0
| even_S n : odd n -> even (n + 1)
with odd : N -> Prop :=
| odd_S n : even n -> odd (n + 1).
\end{minted}
\end{document}
给出