Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
403 changes: 403 additions & 0 deletions Library/ocaml.fmt

Large diffs are not rendered by default.

197 changes: 197 additions & 0 deletions Library/ocamlpoly.fmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
%if False
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% polycode.fmt
%
% better code environment for poly style in lhs2TeX
%
% Permission is granted to include this file (or parts of this file)
% literally into other documents, regardless of the conditions or
% license applying to these documents.
%
% Andres Loeh, February 2013, ver 1.12
%
% TODO: use \[ \] in arrayhs (fleqn problem)
% think about penalties and better pagebreaks
% by using \allowdisplaybreaks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%endif
%if not lhs2tex_ocamlpoly_fmt_read
%let lhs2tex_ocamlpoly_fmt_read = True
%include ocaml.fmt
%
%if style == poly
%
%if False
% The follwing subst replaces the bad default from lhs2TeX.fmt.
% The idea is to just provide the basic structure in the subst, and
% let the rest be handled by a LaTeX environment.
%endif
%
%subst code a = "\begin{hscode}\SaveRestoreHook'n" a "\ColumnHook'n\end{hscode}\resethooks'n"
%
%
% This package provides two environments suitable to take the place
% of hscode, called "plainhscode" and "arrayhscode".
%
% The plain environment surrounds each code block by vertical space,
% and it uses \abovedisplayskip and \belowdisplayskip to get spacing
% similar to formulas. Note that if these dimensions are changed,
% the spacing around displayed math formulas changes as well.
% All code is indented using \leftskip.
%
% Changed 19.08.2004 to reflect changes in colorcode. Should work with
% CodeGroup.sty.
%
\ReadOnlyOnce{polycode.fmt}%
\makeatletter

\newcommand{\hsnewpar}[1]%
{{\parskip=0pt\parindent=0pt\par\vskip #1\noindent}}

% can be used, for instance, to redefine the code size, by setting the
% command to \small or something alike
\newcommand{\hscodestyle}{}

% The command \sethscode can be used to switch the code formatting
% behaviour by mapping the hscode environment in the subst directive
% to a new LaTeX environment.

\newcommand{\sethscode}[1]%
{\expandafter\let\expandafter\hscode\csname #1\endcsname
\expandafter\let\expandafter\endhscode\csname end#1\endcsname}

% "compatibility" mode restores the non-polycode.fmt layout.

\newenvironment{compathscode}%
{\par\noindent
\advance\leftskip\mathindent
\hscodestyle
\let\\=\@@normalcr
\let\hspre\(\let\hspost\)%
\pboxed}%
{\endpboxed\)%
\par\noindent
\ignorespacesafterend}

\newcommand{\compaths}{\sethscode{compathscode}}

% "plain" mode is the proposed default.
% It should now work with \centering.
% This required some changes. The old version
% is still available for reference as oldplainhscode.

\newenvironment{plainhscode}%
{\hsnewpar\abovedisplayskip
\advance\leftskip\mathindent
\hscodestyle
\let\hspre\(\let\hspost\)%
\pboxed}%
{\endpboxed%
\hsnewpar\belowdisplayskip
\ignorespacesafterend}

\newenvironment{oldplainhscode}%
{\hsnewpar\abovedisplayskip
\advance\leftskip\mathindent
\hscodestyle
\let\\=\@@normalcr
\(\pboxed}%
{\endpboxed\)%
\hsnewpar\belowdisplayskip
\ignorespacesafterend}

% Here, we make plainhscode the default environment.

\newcommand{\plainhs}{\sethscode{plainhscode}}
\newcommand{\oldplainhs}{\sethscode{oldplainhscode}}
\plainhs

% The arrayhscode is like plain, but makes use of polytable's
% parray environment which disallows page breaks in code blocks.

\newenvironment{arrayhscode}%
{\hsnewpar\abovedisplayskip
\advance\leftskip\mathindent
\hscodestyle
\let\\=\@@normalcr
\(\parray}%
{\endparray\)%
\hsnewpar\belowdisplayskip
\ignorespacesafterend}

\newcommand{\arrayhs}{\sethscode{arrayhscode}}

% The mathhscode environment also makes use of polytable's parray
% environment. It is supposed to be used only inside math mode
% (I used it to typeset the type rules in my thesis).

\newenvironment{mathhscode}%
{\parray}{\endparray}

\newcommand{\mathhs}{\sethscode{mathhscode}}

% texths is similar to mathhs, but works in text mode.

\newenvironment{texthscode}%
{\(\parray}{\endparray\)}

\newcommand{\texths}{\sethscode{texthscode}}

% The framed environment places code in a framed box.

\def\codeframewidth{\arrayrulewidth}
\RequirePackage{calc}

\newenvironment{framedhscode}%
{\parskip=\abovedisplayskip\par\noindent
\hscodestyle
\arrayrulewidth=\codeframewidth
\tabular{@@{}||p{\linewidth-2\arraycolsep-2\arrayrulewidth-2pt}||@@{}}%
\hline\framedhslinecorrect\\{-1.5ex}%
\let\endoflinesave=\\
\let\\=\@@normalcr
\(\pboxed}%
{\endpboxed\)%
\framedhslinecorrect\endoflinesave{.5ex}\hline
\endtabular
\parskip=\belowdisplayskip\par\noindent
\ignorespacesafterend}

\newcommand{\framedhslinecorrect}[2]%
{#1[#2]}

\newcommand{\framedhs}{\sethscode{framedhscode}}

% The inlinehscode environment is an experimental environment
% that can be used to typeset displayed code inline.

\newenvironment{inlinehscode}%
{\(\def\column##1##2{}%
\let\>\undefined\let\<\undefined\let\\\undefined
\newcommand\>[1][]{}\newcommand\<[1][]{}\newcommand\\[1][]{}%
\def\fromto##1##2##3{##3}%
\def\nextline{}}{\) }%

\newcommand{\inlinehs}{\sethscode{inlinehscode}}

% The joincode environment is a separate environment that
% can be used to surround and thereby connect multiple code
% blocks.

\newenvironment{joincode}%
{\let\orighscode=\hscode
\let\origendhscode=\endhscode
\def\endhscode{\def\hscode{\endgroup\def\@@currenvir{hscode}\\}\begingroup}
%\let\SaveRestoreHook=\empty
%\let\ColumnHook=\empty
%\let\resethooks=\empty
\orighscode\def\hscode{\endgroup\def\@@currenvir{hscode}}}%
{\origendhscode
\global\let\hscode=\orighscode
\global\let\endhscode=\origendhscode}%

\makeatother
\EndFmtInput
%
%endif
%endif
9 changes: 5 additions & 4 deletions src/Directives.lhs
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ Format directives. \NB @%format ( = "(\;"@ is legal.
> tex (Conid s) = subscript Conid s
> tex (Qual [] s) = tex s
> tex (Qual (m:ms) s) = Conid m : tex (Qual ms s)
> -- ks, 03.09.2003: was "tex (Qual m s) = Conid m : tex s";
> -- ks, 03.09.2003: was "tex (Qual m s) = Conid m : tex s";
> -- seems strange though ...
> subscript f s
> subscript f s
> | null t && not (null w) && (null v || head w == '_')
> = underscore f s
> | otherwise = [f (reverse w)
> , TeX False
> (Text ((if not (null v)
> then "_{" ++ reverse v ++ "}"
> then "_{" ++ reverse v ++ "}"
> else ""
> ) ++ reverse t))
> ]
Expand All @@ -97,7 +97,7 @@ Format directives. \NB @%format ( = "(\;"@ is legal.
> (if end then [Varid "_"] else [])

ks, 02.02.2004: I have added implicit formatting via |underscore|.
The above condition should guarantee that it is (almost) only used in
The above condition should guarantee that it is (almost) only used in
cases where previously implicit formatting did not do anything useful.
The function |underscore| typesets an identifier such as
|a_b_c| as $a_{b_{c}}$. TODO: Instead of hard-coded subscripting a
Expand Down Expand Up @@ -172,6 +172,7 @@ because "=" will never occur in a Varid constructor.
> conid = do x <- satisfy isConid; return (string x)
> varsym Agda s = satisfy (\ x -> x == Varsym s || x == Varid s) -- Agda has no symbol/id distinction
> varsym Haskell s = satisfy (== (Varsym s))
> varsym OCaml s = varsym Haskell s
>
> isTeX (TeX _ _) = True
> isTeX _ = False
Expand Down
1 change: 1 addition & 0 deletions src/Document.lhs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Substitution strings.
> sub'code a = Sub "code" [a]
> sub'conid a = Sub "conid" [a]
> sub'varid a = Sub "varid" [a]
> sub'tyvarid a = Sub "tyvarid" [a]
> sub'consym a = Sub "consym" [a]
> sub'varsym a = Sub "varsym" [a]
> sub'backquoted a = Sub "backquoted" [a]
Expand Down
Loading