%
%    This file is part of the Maude 3 interpreter.
%
%    Copyright 2023-2024 SRI International, Menlo Park, CA 94025, USA.
%
%    This program is free software; you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation; either version 2 of the License, or
%    (at your option) any later version.
%
%    This program is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with this program; if not, write to the Free Software
%    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
%
%	LaTeX package for use with the -latex-log= feature.
%	Version 3.5.
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{maude}[2024/04/12 Package for Maude logs]
\RequirePackage{amssymb,extarrows,longtable,tabto,xcolor,verbatim,alltt,seqsplit}
\RequirePackage[T1]{fontenc}
%
%	Spacing
%
\newcommand{\maudeIndent}{\hspace*{1em}}  % for module contents
\newcommand{\maudeBigIndent}{\hspace*{3em}}  % for data in show
\newcommand{\maudeBannerIndent}{\hspace*{5em}}  % for banner
\newcommand{\maudeInterwordSpace}{\hspace{0.4em}}
\newcommand{\maudeTinySpace}{\hspace{0.15em}}
\newcommand{\maudeBigSpace}{\hspace{0.6em}}
\newcommand{\maudeHardSpace}{\hspace*{0.5em}} % doesn't disappear at the start of a new line
\newcommand{\maudeAllowLineBreak}{\linebreak[0]}
\newcommand{\maudeShowSpace}{\vspace{1ex}} % space between a show command and the thing shown
%
%	To get a newline that is not indented we actually start a new paragraph, which means we
%	need to drop out of math mode and use {} to protect from double dollar signs.
%
\newcommand{\maudeNewline}{\)\par\(}
%
%	Font choices.
%
%	Keywords are in bold consistent with usual programming language conventions.
%
\newcommand{\maudeKeyword}[1]{\textbf{#1}}
%
%	Language punctuation is also in bold to match keywords.
%
\newcommand{\maudePunctuation}[1]{\textbf{#1}}
%
%	Maude responses are currently printed in bold to match keywords.
%
\newcommand{\maudeResponse}[1]{\textbf{#1}}
%
%	Modules (including theories) and views are typeset in the document's normal font
%	but at reduced size since these names are often all capital.
%
\newcommand{\maudeModule}[1]{\textnormal{\small #1}}
\newcommand{\maudeView}[1]{\textnormal{\small #1}}
%
%	Sorts can contain all kinds of symbols and so the root name of a sort uses sans serif.
%
\newcommand{\maudeSort}[1]{\textsf{#1}}
%
%	Parameters match sort names because they can appear in unstructured sort names such as X$Elt
%
\newcommand{\maudeParameter}[1]{\textsf{#1}}
%
%	Strings, quoted identifiers and labels can contain all kinds of symbols and so use typewritter.
%
\newcommand{\maudeString}[1]{\texttt{#1}}
\newcommand{\maudeQid}[1]{\texttt{#1}}
%
%	Getting \seqsplit to work with the typewritter font is tricky - we need to drop out of math mode to
%	to use \texttt{} and then jump back into math mode, but account for the possibility that the
%	we may be following or followed by a dollar sign. Thus we can't nest inside {}.
%	Using \text{} or \mbox{} seems to disable \seqsplit{}.
%
\newcommand{\maudeBigString}[1]{\)\texttt{\seqsplit{#1}}\(}
\newcommand{\maudeBigQid}[1]{\)\texttt{\seqsplit{#1}}\(}

\newcommand{\maudeLabel}[1]{\texttt{#1}}
\newcommand{\maudePrefixLabel}[1]{[\texttt{#1}]\maudeInterwordSpace :}
%
%	Numbers are just printed with the math mode default.
%
\newcommand{\maudeNumber}[1]{#1}
%
%	Very large numbers use seqsplit to allow them to be broken anywhere.
%
\newcommand{\maudeBigNumber}[1]{\seqsplit{#1}}
%
%	Normal mode is used for things like the contents of gather attributes and format attributes.
%
\newcommand{\maudeNormal}[1]{\textnormal{#1}}
%
%	Single character operator names use the math mode default, if they are alphabetical or
%	  + - * / < > . ; : | ! ? [ ] ( ) { } & % $ # _
%
\newcommand{\maudeSingleChar}[1]{#1}
%
%	Fancy symbols can only be printed in a limited number of fonts.
%	In particular, italic \ looks like | and italic | looks like /
%	Also italic $ looks ugly. So we typeset operator names containing fancy
%	symbols using sans serif.
%
\newcommand{\maudeSymbolic}[1]{\textsf{#1}}
%
%	Multi-character alpha-numeric operator names use regular italic because math italic has weird spacing.
%
\newcommand{\maudeIdentifier}[1]{\textit{#1}}
%
%	An symbol with the iter attribute has a base name and a number of nested iterations.
%
\newcommand{\maudeIter}[2]{{#1}^{\maudeNumber{#2}}}
%
%	An unparsed token that could be anything.
%
\newcommand{\maudeRaw}[1]{\texttt{#1}}
\newcommand{\maudeBigRaw}[1]{\)\texttt{\seqsplit{#1}}\(}
%
%	Catch all for rare output - use typewritter.
%
\newcommand{\maudeMisc}[1]{\texttt{#1}}
%
%	Character choices.
%
\newcommand{\maudeLeftParen}{(}
\newcommand{\maudeRightParen}{)}
\newcommand{\maudeLeftBracket}{[}
\newcommand{\maudeRightBracket}{]}
\newcommand{\maudeLeftBrace}{\{}
\newcommand{\maudeRightBrace}{\}}
\newcommand{\maudeSingleQuote}{\textquotesingle}
\newcommand{\maudeBackquote}{\textasciigrave}
\newcommand{\maudeFunction}{\rightarrow}  % for op decls
\newcommand{\maudeRenaming}{\;\raisebox{-.5ex}{*}\;}  % module renaming
\newcommand{\maudeSummation}{\,+\,}  % module summation
\newcommand{\maudePartialFunction}{\rightsquigarrow}  % for partial op decls
\newcommand{\maudeConjunction}{\,\wedge\,}  % for conjunctions in conditions
\newcommand{\maudeDisjunction}{\,\vee\,}  % for disjunctions in search
\newcommand{\maudeHasSort}{\,:\,}  % for op, variable decls, mbs and sort test condition fragments
\newcommand{\maudeVariableColon}{\textnormal{:}}  % for forming var:sort names
\newcommand{\maudeEquals}{\,=\,}  % for eqs and equality condition fragments
\newcommand{\maudeRewritesTo}{\,\Rightarrow\,}  % for rls and rewrite condition fragments
\newcommand{\maudeAssign}{\,:=\,}  % for match condition fragments
\newcommand{\maudeParameterColon}{\,::\,}  % for forming parameter :: theory pairs
\newcommand{\maudeLessThan}{<}  % for subsorts
\newcommand{\maudeComma}{,\maudeTinySpace\maudeAllowLineBreak}  % to separate parameters and function arguments
\newcommand{\maudeEndStatement}{\maudeInterwordSpace\maudePunctuation{.}}  % include space and try to avoid preceeding linebreak
\newcommand{\maudeEndCommand}{\maudeInterwordSpace\maudePunctuation{.}}  % include space and try to avoid preceeding linebreak
\newcommand{\maudeDisambigDot}{.}  % for (<term>).<sort>
\newcommand{\maudeMatch}{\,\leq^?\,}
\newcommand{\maudeUnify}{\,=^?\,}
\newcommand{\maudePipe}{\mid}
\newcommand{\maudeTilde}{\raisebox{-.65ex}{\textasciitilde}}
\newcommand{\maudeConstantDecl}{\,:\maudeInterwordSpace\rightarrow} % needed to get the spacing right
\newcommand{\maudeEllipsis}{\ldots}
%
%	Strategy language.
%
\newcommand{\maudeStratAt}{\maudeInterwordSpace\, @\maudeInterwordSpace\,}
\newcommand{\maudeStratAssign}{\,\leftarrow\,}
\newcommand{\maudeStratConcat}{\maudeInterwordSpace;\maudeInterwordSpace}
\newcommand{\maudeStratStar}{*}
\newcommand{\maudeStratPlus}{+}
\newcommand{\maudeStratQuery}{\maudeInterwordSpace ?\maudeInterwordSpace}
\newcommand{\maudeStratColon}{:}
\newcommand{\maudeStratBang}{!}
\newcommand{\maudeStratUnion}{\mid}
%
%	Search
%
\newcommand{\maudeOneStep}{\,\Rightarrow^1}
\newcommand{\maudeAtLeastOneStep}{\,\Rightarrow^+}
\newcommand{\maudeAnySteps}{\,\Rightarrow^*}
\newcommand{\maudeToNormalForm}{\,\Rightarrow^!}
\newcommand{\maudeToBranch}{\,\Rightarrow^\#}
\newcommand{\maudeIsAssigned}{\,\longrightarrow\,}
\newcommand{\maudePathLeft}{\xlongequal{\hspace*{2em}}\hspace*{-0.48em}[\maudeInterwordSpace}
\newcommand{\maudePathRight}{\maudeInterwordSpace]\hspace*{-0.48em}\xLongrightarrow{\hspace*{2em}}}
\newcommand{\maudePathWithLabel}[1]{-\hspace*{-0.48em}-\hspace*{-0.48em}-\hspace*{-0.48em}-\hspace*{-0.45em}-\hspace*{0.2em}#1\hspace*{-0.05em}\xlongrightarrow{\hspace*{2em}}}
\newcommand{\maudePathWithoutLabel}{\xlongrightarrow{\hspace*{4em}}}
\newcommand{\maudeArcArrow}{\Longrightarrow}
%
%	Line breaking.
%
\newcommand{\maudeSpace}{\maudeInterwordSpace\linebreak[0]}  % normally a space is a preferred place for a linebreak
\newcommand{\maudeAllowBreak}{\linebreak[0]}
%
%	Environments.
%
\newenvironment{maudeBanner}{\begin{flushleft}\begin{alltt}}{\end{alltt}\end{flushleft}}
%
%	\hangindent=	sets the indentation of the hanging paragraph
%	\handafter=	sets how many non-indented lines before hangindent is used
%	\parskip=	sets how much vertical space to leave between paragraphs
%
\newenvironment{maudeShowParagraph}{\begin{flushleft}\hangindent=2em\hangafter=1\parskip=0pt}{\end{flushleft}}
\newenvironment{maudeResultParagraph}{\begin{flushleft}\hangindent=2em\hangafter=1\parskip=0pt}{\end{flushleft}}
%
%	Use ASCII sequences in place of math symbols.
%
\DeclareOption{ASCII}{
  \renewcommand{\maudeIter}[2]{#1\textasciicircum #2}
  \renewcommand{\maudeFunction}{\maudeBigSpace\textnormal{-->}\maudeBigSpace}
  \renewcommand{\maudePartialFunction}{\textnormal{\maudeTilde >}\maudeBigSpace}
  \renewcommand{\maudeConstantDecl}{\maudeInterwordSpace :\maudeInterwordSpace\textnormal{-->}\maudeBigSpace} % needed to get the spacing right
  \renewcommand{\maudeConjunction}{\maudeBigSpace/\backslash\maudeBigSpace}
  \renewcommand{\maudeDisjunction}{\maudeBigSpace\backslash/\maudeBigSpace}
  \renewcommand{\maudeRewritesTo}{\maudeBigSpace\textnormal{=>}\maudeBigSpace}
  \renewcommand{\maudeMatch}{\,\textnormal{<=?}\,}
  \renewcommand{\maudeUnify}{\,\textnormal{=?}\,}
  \renewcommand{\maudeStratAssign}{\,\textnormal{<--},}
  \renewcommand{\maudeOneStep}{\maudeBigSpace\textnormal{=>1}\maudeBigSpace}
  \renewcommand{\maudeAtLeastOneStep}{\maudeBigSpace\textnormal{=>+}\maudeBigSpace}
  \renewcommand{\maudeAnySteps}{\maudeBigSpace\textnormal{=>*}\maudeBigSpace}
  \renewcommand{\maudeToNormalForm}{\maudeBigSpace\textnormal{=>!}\maudeBigSpace}
  \renewcommand{\maudeToBranch}{\maudeBigSpace\textnormal{=>\#}\maudeBigSpace}
  \renewcommand{\maudeIsAssigned}{\maudeBigSpace\textnormal{--\,-->}\maudeBigSpace}
  \renewcommand{\maudePathLeft}{\textnormal{===[}\maudeBigSpace}
  \renewcommand{\maudePathRight}{\maudeBigSpace\textnormal{]===>}}
  \renewcommand{\maudePathWithLabel}[1]{\textnormal{--\,--\,--}\maudeBigSpace#1\maudeBigSpace\textnormal{--\,--\,-->}}
  \renewcommand{\maudePathWithoutLabel}{\textnormal{--\,--\,--\,--\,--\,-->}}
  \renewcommand{\maudeArcArrow}{\maudeBigSpace\textnormal{===>}\maudeBigSpace}
}
\ProcessOptions\relax
