Skip to content

Commit

Permalink
Added support for outer spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
mlhetland committed Jun 30, 2019
1 parent 7c8a013 commit c7cf8b1
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 66 deletions.
30 changes: 1 addition & 29 deletions doc/fig/hilitefig.tex
Original file line number Diff line number Diff line change
@@ -1,39 +1,11 @@
\documentclass[beamer,preview,multi]{standalone}
% \documentclass{beamer}
% \usepackage{mlh}
\usepackage{pseudo}
% \pseudoset{kw, hpad, kwfont=\bfseries}
% \pseudoset{kw, hpad, kwfont=\bfseries}
\pseudoset{hpad}
\pseudoset{hpad, compact}

\standaloneenv{myenv}

% XXX My \== gets ruined by the standalone preview option for some reason.

\begin{document}

% \begin{standaloneframe}
% \begin{myenv}
% \begin{pseudo}[hpad] <1-3>
% if $x < y$ \\+ <2> [bol=\onslide<2->]
% $\id{foo} = 2$ \\- [hl<3>, bol=\onslide<3->]
% howdy
% \end{pseudo}
% \end{myenv}
% \end{standaloneframe}

% \begin{standaloneframe}
% \begin{myenv}
% \begin{pseudo} <1,4>
% while $a \neq b$ \\+ <2>
% if $a > b$ \\+
% $a = a - b$ \\- <3>
% else $b = b - a$ \\- <5>
% return $a$
% \end{pseudo}
% \end{myenv}
% \end{standaloneframe}

\begin{standaloneframe}
\begin{myenv}
\begin{pseudo}
Expand Down
37 changes: 1 addition & 36 deletions doc/fig/pausefig.tex
Original file line number Diff line number Diff line change
@@ -1,48 +1,14 @@
\documentclass[beamer,preview,multi]{standalone}
% \documentclass{beamer}

% \usepackage[notmath]{sansmathfonts}
% \usepackage{mlh}
\usepackage{pseudo}
% \pseudoset{kw, hpad, kwfont=\bfseries, prfont=\sffamily}

% \usepackage{expl3,xparse}
%
% \makeatletter
% \ExplSyntaxOn
%
% \int_new:N \g_@@_row_num_int
%
% \cs_new:Nn \@@_onslide: {
% \int_gincr:N \g_@@_row_num_int
% \onslide<\g_@@_row_num_int->
% }
%
% \NewDocumentCommand \pseudostartslide {} {
% \int_zero:N \g_@@_row_num_int
% }
%
% \cs_set_eq:NN \pseudoonslide \@@_onslide:
% % \cs_set_eq:NN \oldctrcmd \__pseudo_old_counter_cmds:
%
% \ExplSyntaxOff
% \makeatother
\pseudoset{compact}

\setbeamercovered{transparent}
\standaloneenv{myenv}

\begin{document}


% \begin{frame}
\begin{standaloneframe}
\begin{myenv}
% XXX Begins on line 2, as it hasn't been incremented yet. And several
% solutions (like \onslide<+-> or \pause) just break down.
% XXX Working on an "uncover" option. Should probably have a similar thing
% that dims out the previous ones -- or maybe even a "dim" key...
%
% XXX Use the suffix package to get the starred versions
\begin{pseudo}[pause]
Eeny \\
Meeny \\
Expand All @@ -51,6 +17,5 @@
\end{pseudo}
\end{myenv}
\end{standaloneframe}
% \end{frame}

\end{document}
Binary file modified doc/pseudo.pdf
Binary file not shown.
165 changes: 165 additions & 0 deletions doc/pseudo.tex
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,15 @@ \section{Overview}
\end{texexp}

\noindent
Spacing is handled similarly to in \LaTeX\ lists, with \cs{topsep} and
\cs{parskip} added before and after, as well as \cs{partopsep} whenever the
environment starts a new paragraph. The left margin (how much the pseudocode
is indented wrt.\ the surrounding text) is set by the \refk{left-margin} key
(initially \code{0pt}).\footnote{If \refe{pseudo} occurs in a box such as
\code{fbox}, or a \pkg[https://ctan.org/pkg/pgf]{tikz} node, this spacing is
dropped.}

\medskip\noindent
There are also some styling commands for special elements of the pseudocode:

\begin{texexp}
Expand Down Expand Up @@ -1044,6 +1053,45 @@ \subsection{Command and key reference}
\fontcmd{cn}
\end{docCommand}

\begin{docKey}{compact}{\,=\,\meta{boolean}}{default \code{true}, initially
\code{false}}

\parindent1.5em
\noindent
The \refe{pseudo} environment emulates the built-in \LaTeX\ lists when it
comes to spacing above and below, in normal text. If the environment is
part of an ongoing paragraph, paragraphs will be inserted above and below,
along with whitespace specified by \refk{topsep} and \refk{parskip}. If
the environment begins a paragraph of its own, additional whitespace is
added, as specified by \refk{partopsep}. It is also possible to specify
space to insert to the left of the environment, using \refk{left-margin}.

However, these spacing commands don't work well inside \cs{mbox},
\cs{fbox}, etc. To avoid getting into trouble, \pkg{pseudo} determines
that the environment should be \emph{compact}, and drop this surrounding
space, if we're in inner horizontal mode at the beginning of the
environment.

\begin{texexp}
% In preamble:
% \usepackage{tikz}
\begin{tikzpicture}
\draw (0,0) node [draw] {%
\begin{pseudo}
if we're in a node \\+
there's no added space
\end{pseudo}};
\end{tikzpicture}
\end{texexp}

This may not be enough, however. For example, if you're using
\pkg[https://ctan.org/pkg/standalone]{standalone} to produce individual
pseudocode images, this compactness will \emph{not} be triggered
automatically. In such cases, you can override the behavior using the
\refk{compact} trigger, manually specifying whether you want the
pseudocode to be compact or not.
\end{docKey}

\begin{docCommand}{ct}{\marg{text}}
Indicates that \meta{text} is a comment, \ct{typeset like this}. You can
customize the comment appearance using \refk{ctfont}, \refk{ct-left} and
Expand Down Expand Up @@ -1551,6 +1599,40 @@ \subsection{Command and key reference}
get the results you want by specifying your own \refk{preamble} in full.
\end{docKey}

\begin{docKey}{left-margin}{\,=\,\meta{length}}{\initialkeyvalue{\code{0pt}}}
Sets the left margin of the \code{pseudo} environment, i.e., how far it is
indented wrt.\ the surrounding text:
\begin{texexp}
Lorem ipsum dolor sit amet:

\begin{pseudo}[left-margin=1.25em]
consetetur sadipscing elitr \\
sed diam nonumy eirmod tempor
\end{pseudo}

Invidunt ut labore et dolore magna.
\end{texexp}

To have the environment indented as (the beginning of) any normal paragraph,
you could use \code*{left-margin = \cs{parindent}}. Note that
\refk{left-margin}, as well as the spacing above and below the \refe{pseudo}
environment, is turned off inside \cs{mbox} and the like:
\begin{texexp}
\pseudoset{left-margin=1cm} % Won't affect box contents
\fbox{\begin{pseudo*}
I'm a livin' in a box \\
I'm a livin' in a cardboard box
\end{pseudo*}}
\end{texexp}
Note that as opposed to \refk{topsep}, \refk{parskip} and \refk{partopsep}, we
are \emph{not} working with one of the built-in list spacing commands;
\cs{leftmargin} has no effect on this key (which is why the hyphenated naming
style of other keys such as \refk{label-align} or \refk{indent-text} is also
adopted for \refk{left-margin}).
%
See also \refk{compact}.
\end{docKey}

\begin{docKey}{line-height}{\,=\,\meta{factor}}{\initialkeyvalue{\code{1}}}
The \meta{factor} with which to multiply the ordinary line height. For
simple, sparse pseudocode, the oridnary line height works well, but if
Expand All @@ -1569,6 +1651,16 @@ \subsection{Command and key reference}
See also \refc{tn}.
\end{docCommand}

\begin{docKey}{parskip}{\,=\,\meta{length}}{\initialkeyvalue{\cs{parskip}}}
Sets a \pkg{pseudo}-local copy of \cs{parskip} for use in vertical spacing
above and below the \refe{pseudo} environment. See also \refk{compact}.
\end{docKey}

\begin{docKey}{partopsep}{\,=\,\meta{length}}{\initialkeyvalue{\cs{partopsep}}}
Sets a \pkg{pseudo}-local copy of \cs{partopsep} for use in vertical
spacing above and below the \refe{pseudo} environment. See also \refk{compact}.
\end{docKey}

\begin{docKey}{pause}{}{\novaluekey}
Equivalent to \code*{\refk{eol-append} = \cs{pause}} (see \cref{p:pause}).
\end{docKey}
Expand Down Expand Up @@ -1856,6 +1948,11 @@ \subsection{Command and key reference}
\shortcutted{tn}{textnormal}
\end{docCommand}
\begin{docKey}{topsep}{\,=\,\meta{length}}{\initialkeyvalue{\cs{topsep}}}
Sets a \pkg{pseudo}-local copy of \cs{topsep} for use in vertical spacing
above and below the \refe{pseudo} environment. See also \refk{compact}.
\end{docKey}
\begin{docKey}{unknown}{}{}
Unknown keys are checked for \pkg[https://ctan.org/pkg/beamer]{beamer}
overlay specifications. That is, if an unknown key has the form
Expand Down Expand Up @@ -2894,6 +2991,9 @@ \subsection{Options}
hsep .tl_set:N = \l_@@_hsep_tl,
hsep .initial:n = .75em,
left-margin .tl_set:N = \l_@@_left_margin_tl,
left-margin .initial:n = 0pt,
label .tl_set:N = \l_@@_label_tl,
label .initial:n = \arabic*,
Expand Down Expand Up @@ -3042,6 +3142,32 @@ \subsection{Options}
end-tabular .tl_set:N = \l_@@_end_tabular_tl,
end-tabular .initial:n = \end{tabular},
\end{source}
\paragraph{List-like spacing.} Space above and below is handled similarly to
in the built-in \LaTeX\ lists, with the option of locally overriding
\cs{topsep}, \cs{parskip} and \cs{partopsep}, with \refk{compact} used to
control the presence of this spacing (overriding the ordinary automatic choice
based on the current mode).
\begin{source}
topsep .tl_set:N = \l_@@_topsep_tl,
topsep .initial:n = { \topsep },
parskip .tl_set:N = \l_@@_parskip_tl,
parskip .initial:n = { \parskip },
partopsep .tl_set:N = \l_@@_partopsep_tl,
partopsep .initial:n = { \partopsep },
compact .meta:n = {
compact-val = #1,
compact-def = true,
},
compact .default:n = true,
% For internal use:
compact-val .bool_set:N = \l_@@_compact_bool,
compact-def .bool_set:N = \l_@@_compact_def_bool,
\end{source}
\paragraph{Details.} Finally, some tweakable parameters.
\begin{source}
eqs-scale .fp_set:N = \l_@@_eqs_scale_fp,
Expand All @@ -3053,6 +3179,7 @@ \subsection{Options}
eqs-pad .tl_set:N = \l_@@_eqs_pad_tl,
eqs-pad .initial:n = 0.28mu,
}
\end{source}
%
Expand Down Expand Up @@ -3290,6 +3417,7 @@ \subsection{The \texttt{pseudo} environment}
\NewDocumentEnvironment { pseudo } { !+o !s d<> +O{ } } {
\group_begin:
\@@_gsave_as:NN \\ \c_@@_saved_cr_cs
\@@_gsave_as:NN \= \c_@@_saved_eq_cs
Expand All @@ -3304,6 +3432,32 @@ \subsection{The \texttt{pseudo} environment}
}
\@@_set_indent_length:
% If not manually set as compact/noncompact, set automatically:
\bool_if:NF \l_@@_compact_def_bool {
\bool_set:Nn \l_@@_compact_bool {
\mode_if_horizontal_p: && \mode_if_inner_p:
}
}
\bool_if:nF { \l_@@_compact_bool } {
\skip_set:Nn \l_tmpa_skip {
\l_@@_topsep_tl + \l_@@_parskip_tl
}
\mode_if_vertical:TF {
\skip_add:Nn \l_tmpa_skip { \l_@@_partopsep_tl }
} {
\unskip \par
}
\addvspace { \l_tmpa_skip }
\noindent
\skip_horizontal:n{ \dim_eval:n { \l_@@_left_margin_tl } }
}
\dim_set:Nn \tabcolsep { \l_@@_hsep_tl / 2 }
\tl_set:Nn \arraystretch
{ \fp_to_decimal:n { \l_@@_line_height_fp } }
Expand Down Expand Up @@ -3356,6 +3510,17 @@ \subsection{The \texttt{pseudo} environment}
\tl_use:N \l_@@_end_tabular_tl
\bool_if:nF { \l_@@_compact_bool } {
\mode_if_vertical:F {
\unskip \par
}
\addvspace{ \l_tmpa_skip }
}
\group_end:
}
Expand Down
Loading

0 comments on commit c7cf8b1

Please sign in to comment.