1 Unicode Translation
default-ops
operator/ c
operators/ c
content->latex-content
translate-char
overload-op*
math-mode
in-math
unmath
2 General utilities
exact
m
um
mp
renewcommand
bracket
curlies
parens
env
tenv
envalign*
align*
array
style-matrix
matrix
3 amsthm utilities
mdef
mthm
mlem
mprop
mcor
mnotation
unthm
tprf
ntthm
ntlem
ntprf
parthm
parlem
parprop
parunthm
parprf
4 listings utilities
lstlisting
lstset
5 mathpartir utilities
mathpar
6 pfsteps utilities
by Cases
bc-case
bc-otherwise
7 Miscellaneous
graybox
Version: 5.3.0.11

Scribble + LaTeX utils

This library provides support for an assortment of LaTeX environments, particularly for mathematics rendering. Most of these functions/macros render LaTeX strings rather than use Scribble’s elements to get the same effect. This is primarily because brackets are not supported (for rendering tabular environments, say). These strings are wrapped in a LaTeX identity macro, and lead to some nasty interop with environments that parse their bodies, such as mathpar (from mathpartir) and lstlisting (from listings). Thus this collection of utils supports some of those special environments specifically.

1 Unicode Translation

Default operations for Unicode composing characters. Specifically #\̂ for \hat, #\̃ for \tilde, #\̇ for \dot, and #\̸ for \centernot (requires centernot package).

Contract for a composing character operation. The translator provides the character before the composing character leading to this operator’s use, the entire string, and the current string position. If the composing character is consumed by the operation, return the string position plus 1.

For example, the operator for #\̂ (Unicode composing hat) is
(λ (c str i)
   (values (format "\\hat{~a}{}" (in-math (translate-char c)))
           (+ i 1)))

Contracts a hash of char? to operator/c.

procedure

(content->latex-content e    
  [#:operators ophash])  content?
  e : content?
  ophash : operators/c = default-ops
Maps over e and translates strings to the proper LaTeX commands, allowing for composing characters to be manipulated according to ophash. Only does post-composing operations, not pre-composing.

procedure

(translate-char c)  string?

  c : char?
The Unicode character to LaTeX command procedure.

procedure

(overload-op* key value ... ...)  operators/c

  key : char?
  value : operator/c
Extends or overrides default-ops.

parameter

(math-mode)  boolean?

(math-mode in-math?)  void?
  in-math? : boolean?
Parameter determines how math is rendered.

syntax

(in-math items ...+)

Renders items in a context where math-mode is #t

syntax

(unmath items ...+)

Renders items in a context where math-mode is #f

2 General utilities

procedure

(exact [#:operators operators] item ...)  content?

  operators : operators/c = default-ops
  item : content?
Core form that renders all input to text and wraps it in \identity. If the content contains Unicode characters, then many of them will be rendered to the right LaTeX command. Some composing Unicode characters are supported too. See overload-op*.

This Unicode translation does not play nicely with delayed-element? or part-relative-element? since I don’t know how to correctly wrap these to do the translation.

syntax

(m item ...)

Renders items in math mode with the same guarantees as exact. Uses of m nest, using an internal parameter in-math that is maintained by the different forms in utils. It does not use the \ensuremath command.

syntax

(um item ...)

Renders items ensuring not in math mode (uses \mbox).

syntax

(mp item ...)

Like m, only uses \[...\] instead of $...$.

procedure

(renewcommand left right)  content?

  left : content?
  right : content?
Wrapper for LaTeX’s \renewcommand.

struct

(struct bracket (element)
  #:extra-constructor-name make-bracket)
  element : content?

struct

(struct curlies (element)
  #:extra-constructor-name make-curlies)
  element : content?

struct

(struct parens (element)
  #:extra-constructor-name make-parens)
  element : content?
Structures that are intepreted by env to wrap the given element in brackets, braces or parens respectively.

procedure

(env t [#:opt optional] items ...)  content?

  t : content?
  optional : (listof (or/c brackets? curlies? parens?)) = '()
  items : content?
Wraps items in the t environment, and optionally renders an assortment of wrapped content to allow for inputting optional arguments to the environment. For example, \begin{array}{cc}l&r\end{array} is (env "array" (list (curlies "cc")) "l&r").

procedure

(tenv t title items ...)  content?

  t : content?
  title : content?
  items : content?
Uses env in an idiomatic way, giving a “title” to an environment by using (list (brackets title)) as the optional argument.

syntax

(envalign* items ...)

Uses env for the align* environment. Sets math mode parameter to work correctly with m. Expects items to be expressions that evaluate to content?.

syntax

(align* (args ...) ...)

Like envalign*, only inserts the & and \\ between individual args and list of args, respectively.

procedure

(array style items ...)  content?

  style : content?
  items : content?
Renders items in an array environment with the given style. Example above in env takes the form (array "cc" "l&r").

syntax

(style-matrix (s:style ...) (args ...) ...)

Uses same separation as align*, only creates an array with the given style, which is a sequence of the identifiers l, r, c or bar.

syntax

(matrix (args ...) ...)

Uses style-matrix with all left-aligned colunms.

3 amsthm utilities

procedure

(mdef title #:tag tag items ...)  content?

  title : content?
  tag : (or/c content? #f)
  items : content?
Uses definition theorem environment (must be declared in style file: \newtheorem{definition}{Definition}) to give a definition. To use a LaTeX label (not a scribble one!), provide an argument to #:tag.

procedure

(mthm title #:tag tag items ...)  content?

  title : content?
  tag : (or/c content? #f)
  items : content?

procedure

(mlem title #:tag tag items ...)  content?

  title : content?
  tag : (or/c content? #f)
  items : content?

procedure

(mprop title #:tag tag items ...)  content?

  title : content?
  tag : (or/c content? #f)
  items : content?

procedure

(mcor title #:tag tag items ...)  content?

  title : content?
  tag : (or/c content? #f)
  items : content?

procedure

(mnotation title #:tag tag items ...)  content?

  title : content?
  tag : (or/c content? #f)
  items : content?

procedure

(unthm title #:tag tag items ...)  content?

  title : content?
  tag : (or/c content? #f)
  items : content?
Like mdef, only use theorem, lemma, property, corollary, notation and untheorem (used for "Conjecture") theorem environments respectively.

procedure

(tprf title items ...)  content?

  title : content?
  items : content?
Renders items in the proof environment with the given title. Proof does not need declaration like theorem, etc.

procedure

(ntthm items ...)  content?

  items : content?

procedure

(ntlem items ...)  content?

  items : content?

procedure

(ntprf items ...)  content?

  items : content?
Like mthm, mlem and tprf, only with no titles or tags. ntprf uses the proof environment.

procedure

(parthm title #:tag tag items ...)  content?

  title : content?
  tag : (or/c content? #f)
  items : content?
Like mthm, only allows blocks (e.g. uses of itemlist) in items. It wraps content in make-paragraph and makes sure not to add more paragraphs than it needs.

procedure

(parlem title #:tag tag items ...)  content?

  title : content?
  tag : (or/c content? #f)
  items : content?

procedure

(parprop title #:tag tag items ...)  content?

  title : content?
  tag : (or/c content? #f)
  items : content?

procedure

(parunthm title #:tag tag items ...)  content?

  title : content?
  tag : (or/c content? #f)
  items : content?

procedure

(parprf #:tag tag items ...)  content?

  tag : (or/c content? #f)
  items : content?
Like parthm, only for mlem, mprop, unthm and ntprf respectively.

4 listings utilities

procedure

(lstlisting #:math-escape? math-escape?    
  items ...)  content?
  math-escape? : #f
  items : content?
Renders items in lstlisting environment. Uses extra trickery with boxes to get it to work with scribble. Give #t for #:math-escape? to get math rendering for $...$.

procedure

(lstset [#:basicstyle basicstyle    
  #:keywordstyle keywordstyle    
  #:identifierstyle identifierstyle    
  #:commentstyle commentstyle    
  #:stringstyle stringstyle    
  #:showstringspaces showstringspaces    
  #:numbers numbers    
  #:numberstyle numberstyle    
  #:numberblanklines numberblanklines    
  #:stepnumber stepnumber    
  #:numbersep numbersep    
  #:backgroundcolor backgroundcolor    
  #:showspaces showspaces    
  #:showtabs showtabs    
  #:frame frame    
  #:label label    
  #:rulecolor rulecolor    
  #:tabsize tabsize    
  #:language language    
  #:caption caption    
  #:captionpos captionpos    
  #:breaklines breaklines    
  #:breakatwhitespace breakatwhitespace    
  #:title title    
  #:escapeinside escapeinside    
  #:morekeywords morekeywords    
  #:moredelim moredelim    
  #:xleftmargin xleftmargin    
  #:xrightmargin xrightmargin])  content?
  basicstyle : (or/c content? #f) = #f
  keywordstyle : (or/c content? #f) = #f
  identifierstyle : (or/c content? #f) = #f
  commentstyle : (or/c content? #f) = #f
  stringstyle : (or/c content? #f) = #f
  showstringspaces : (or/c content? #f) = #f
  numbers : (or/c content? #f) = #f
  numberstyle : (or/c content? #f) = #f
  numberblanklines : (or/c content? #f) = #f
  stepnumber : (or/c content? #f) = #f
  numbersep : (or/c content? #f) = #f
  backgroundcolor : (or/c content? #f) = #f
  showspaces : (or/c content? #f) = #f
  showtabs : (or/c content? #f) = #f
  frame : (or/c content? #f) = #f
  label : (or/c content? #f) = #f
  rulecolor : (or/c content? #f) = #f
  tabsize : (or/c content? #f) = #f
  language : (or/c content? #f) = #f
  caption : (or/c content? #f) = #f
  captionpos : (or/c content? #f) = #f
  breaklines : (or/c content? #f) = #f
  breakatwhitespace : (or/c content? #f) = #f
  title : (or/c content? #f) = #f
  escapeinside : (or/c content? #f) = #f
  morekeywords : (or/c content? #f) = #f
  moredelim : (or/c content? #f) = #f
  xleftmargin : (or/c content? #f) = #f
  xrightmargin : (or/c content? #f) = #f
Provides a subset of possible inputs to the extensive \lstset macro. See listings documentation for usage.

5 mathpartir utilities

syntax

(mathpar items ...)

Renders items in mathpar environment. Uses extra trickery with boxes to get it to work with scribble.

6 pfsteps utilities

Jesse Tov has an excellent LaTeX package for typesetting rigorous proofs.. Given his pfsteps package is included in the extra style latex file, you can use the following forms to interact with it.

procedure

(byCases items ...)  content?

  items : content?
Form for case analysis. To be used with bc-case and bc-otherwise.

syntax

(bc-case title items ...)

For use in byCases items. Gives case a title (e.g. "Base case") and the following proof.

procedure

(bc-otherwise items ...)  content?

  items : content?
For use as the last of the byCases items. Instead of saying "Case [title]" it says "Otherwise". It does not have to be used.

7 Miscellaneous

Random stuff I threw in for papers.

procedure

(graybox elm)  content?

  elm : content?
Requires color package. Gives elm a light gray background color.