Skip to content

Commit 3325d55

Browse files
committed
latex: Rewrite alectryon@hyp to improve hypothesis display
The new version measures the type of the hypothesis to attempt to fit it within a line, and forces it to wrap if it doesn't fit.
1 parent 3433e36 commit 3325d55

File tree

9 files changed

+446
-931
lines changed

9 files changed

+446
-931
lines changed

alectryon/assets/alectryon.sty

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
\setlength{\alectryonMargin}{0.3em}
55
\newlength{\alectryonRuleSkip}
66
\setlength{\alectryonRuleSkip}{0.3em}
7+
\newlength{\alectryonHypH}
8+
\setlength{\alectryonHypH}{2em}
9+
\newlength{\alectryonHypV}
10+
\setlength{\alectryonHypV}{0.6em}
711

812
\definecolor{alectryon@tango@light@aluminium}{HTML}{EEEEEC}
913
\definecolor{alectryon@tango@medium@aluminium}{HTML}{D3D7CF}
@@ -49,7 +53,38 @@
4953
% \alectryon@parsetup removes paragraph skips and indents
5054
\newcommand*{\alectryon@parsetup}
5155
{\setlength{\parskip}{0pt}
52-
\setlength{\parindent}{0pt}}
56+
\setlength{\parindent}{0pt}}
57+
% \alectryon@setlineskip{LENGTH} ensures that lines are LENGTH apart
58+
\newlength{\alectryon@@lineskip}
59+
\newlength{\alectryon@@lineskiplimit}
60+
\newcommand{\alectryon@setlineskip}[1]
61+
{\setlength{\alectryon@@lineskip}{\lineskip}%
62+
\setlength{\lineskip}{#1}%
63+
\setlength{\alectryon@@lineskiplimit}{\lineskiplimit}%
64+
\setlength{\lineskiplimit}{#1}}
65+
% \alectryon@resetlineskip resets line-skip settings
66+
\newcommand{\alectryon@resetlineskip}
67+
{\setlength{\lineskip}{\alectryon@@lineskip}%
68+
\setlength{\lineskiplimit}{\alectryon@@lineskiplimit}}
69+
70+
% \alectryon@parbox{WIDTH}{TEXT} wraps TEXT in a box with standard line skip
71+
\newcommand*{\alectryon@parbox}[2]
72+
{{\alectryon@resetlineskip%
73+
% \setlength{\fboxsep}{0pt}%
74+
% \fbox{%
75+
\parbox[t][][t]{\alectryon@@width}{#2}%
76+
% }%
77+
}}
78+
% \alectryon@maxwidth{WIDTH}{TEXT} typesets TEXT as a paragraph of maximum width WIDTH
79+
\newlength{\alectryon@@width@initial}
80+
\newlength{\alectryon@@width}
81+
\newcommand*{\alectryon@maxwidth}[2]
82+
{\settowidth{\alectryon@@width@initial}
83+
{\begin{tabular}[t]{@{}l@{}}#2\end{tabular}}%
84+
\setlength{\alectryon@@width}
85+
{\ifdim\alectryon@@width@initial>#1 #1\else\alectryon@@width@initial\fi}%
86+
\alectryon@parbox{\alectryon@@width}{#2}}
87+
5388
\newcommand{\alectryon@prelude}
5489
{\alectryon@fontsetup
5590
\alectryon@parsetup
@@ -63,9 +98,8 @@
6398
\tcbsetforeverylayer{boxsep=0pt, left=\alectryonMargin, right=\alectryonMargin, top=\alectryonMargin, bottom=\alectryonMargin}
6499
\tcbsetforeverylayer{boxrule=0pt, sharp corners}}
65100

66-
\newcommand{\alectryon@hypn}[1]{\textbf{#1}}
67101
\newcommand{\alectryon@par}{\leavevmode\par\ignorespaces}
68-
\newcommand{\alectryon@cr}{\-\cr\ignorespaces}
102+
\newcommand{\alectryon@newline}{\-\\\ignorespaces}
69103
\newcommand{\alectryon@vsep}{\vspace{0.15em}}
70104
\newcommand{\alectryon@sep}{\relax}
71105
\newcommand{\alectryon@nl}{\alectryon@par}
@@ -118,17 +152,20 @@
118152
{\alectryon@goal@rule}
119153
\alectryon@newenvironment{hyps}
120154
{\alectryon@hyphens%
121-
\begin{minipage}{\linewidth}%
122-
\alectryon@raggedright
123-
\advance\baselineskip by \alectryonRuleSkip\relax}
124-
{\end{minipage}} % Minipage needed for baselineskip adjustment
125-
{\discretionary{}{}{\hbox{\hspace{2em}}}}
126-
\alectryon@newenvironment[1]{hyp}
127-
{\mbox{#1}:\nobreak\hspace{0.25em}\nobreak%
128-
\def\alectryon@nl{\alectryon@cr}%
129-
\begin{tabular}[t]{@{}l@{}}}
130-
{\end{tabular}}
131-
{}
155+
\alectryon@raggedright%
156+
\alectryon@setlineskip{\alectryonHypV}}
157+
{\par}
158+
{\discretionary{}{}{\hbox{\hspace{\alectryonHypH}}}}
159+
\newcommand*{\alectryon@hyp}[3][]
160+
{{\def\alectryon@nl{\alectryon@newline}%
161+
\alectryon@maxwidth{\textwidth}
162+
{{\alectryon@hypn{#2}\hspace{0.25em plus 1fil}\penalty500%
163+
\def\alectryon@space{\rule{0pt}{0pt} \rule{0pt}{0pt}}%
164+
\lineskiplimit=\alectryonRuleSkip%
165+
\lineskip=\alectryonRuleSkip%
166+
\alectryon@maxwidth{\dimexpr\textwidth\relax}{#3}}}}}
167+
\newcommand*{\alectryon@hypn}[1]
168+
{\mbox{\textbf{#1}:}}
132169
\alectryon@newenvironment{extragoals}{}{}
133170
{\par\alectryon@vsep}
134171
\alectryon@newenvironment{messages}{\begin{alectryon@outer}}{\end{alectryon@outer}}

alectryon/latex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ def gen_goal(self, goal):
180180
with environments.goal():
181181
with environments.hyps():
182182
for hyp in goal.hypotheses:
183-
names = macros.hypn(", ".join(hyp.names))
183+
names = PlainText(", ".join(hyp.names))
184184
htype = self.highlight(hyp.type)
185185
hbody = self.highlight(hyp.body) if hyp.body else []
186-
environments.hyp(*htype, args=[names], optargs=hbody, verbatim=True)
186+
macros.hyp(*htype, args=[names], optargs=hbody, verbatim=True)
187187
environments.conclusion(*self.highlight(goal.conclusion), verbatim=True)
188188

189189
def gen_goals(self, first, more):

recipes/_output/api.rst.out

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,7 @@ Expecting:
186186
\begin{goals}
187187
\begin{goal}
188188
\begin{hyps}
189-
\begin{hyp}{\hypn{H}}
190-
\PY{k+kt}{False}
191-
\end{hyp}
189+
\hyp{H}{\PY{k+kt}{False}}
192190
\end{hyps}
193191
\sep
194192
\begin{conclusion}

recipes/_output/fragments.snippets.tex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@
5858
\begin{goals}
5959
\begin{goal}
6060
\begin{hyps}
61-
\begin{hyp}{\hypn{H}}
62-
\PY{k+kt}{False}
63-
\end{hyp}
61+
\hyp{H}{\PY{k+kt}{False}}
6462
\end{hyps}
6563
\sep
6664
\begin{conclusion}

0 commit comments

Comments
 (0)