Skip to content

Instantly share code, notes, and snippets.

@bencrowder
Last active June 3, 2016 15:23
Show Gist options
  • Save bencrowder/37cc81fbcc7acbb07c55da8bc5f73260 to your computer and use it in GitHub Desktop.
Save bencrowder/37cc81fbcc7acbb07c55da8bc5f73260 to your computer and use it in GitHub Desktop.
rule
size 6x9";
# alternates
size letter;
size 210x297mm;
size a4;
font Arno Pro, 10/13pt;
margin 1";
inner-margin .75"; # overrides earlier margin value
endrule
# Named rule (for use later)
rule @times
find \dx\d : replace \d × \d
endrule @times
rule @year-labels
# Find "a.d." and turn on the smcp OpenType feature
find a.d. : feature smcp;
# alternate way
find [b.c. | b.c.e. | c.e. | a.d.] : feature smcp;
endrule
# Exceptions
rule
# If a.d. is found in heading style text, don't run @year-labels on it
find a.d. (style=heading) : ignore @year-labels;
# Find a specific "m.a.d." and don't run @year-labels on it
# This selector language needs a lot of work
find /chapter:4/paragraph:2/word:[m.a.d.] : ignore @year-labels;
# Usually, though, you'd want to revise the general rule like this
# Only run the rule if it's by itself (word boundaries) and not a heading
find \wa.d.\w (style!=heading) : feature smcp;
endrule
rule @paragraph-indents
# Indent first line of all paragraphs 1.25em;
find %paragraph : initial-indent 1.25em;
# Override for first paragraph of a section/chapter
find %paragraph:nth(1) : initial-indent 0;
# Paragraphs following tables aren't indented
find %table + %paragraph : initial-indent 0;
# Hanging indents for paragraphs with hanging tag
find %paragraph.hanging : hanging-indent .125";
endrule
# Tracking/kerning
rule
# Find sequential uppercase and bump tracking up
find [A-Z]+ | tracking 50;
# Find V followed by a and kern -25
find Va | kern -25;
endrule
# Coptic (named Unicode range)
range @coptic
u+2c80 .. u+2cff;
u+03e2 .. u+03ee;
u+03ef; # separated for demo purposes
endrange
rule @coptic-font
# Any characters in the Coptic range should be set in Antinoou
find range @coptic : font Antinoou, 24/28pt, dlig;
endrule
# Unicode properties
rule @numbers
# Replace any numbers with old-style figures
find [ unicode.Nd | unicode.No ] : feature onum;
endrule
# Masters
master @a
frame ...; # incomplete, but this part would have text frames
endmaster
# Apply masters
rule
# All pages get master @a by default
page * : master @a;
# Remove master for pages i-iv
page i-iv : master none;
# Ignore @paragraph-indents rule on page 9
page 9 : ignore @paragraph-indents;
# Set data to be put into masters
data @main, @index;
# Variable used for running heads
$title War and Peace;
# Set running heads
# (@inside-header etc. are frames in the master)
page.odd : @inside-header $pagenum;
page.odd : @outside-header $section; # set in data
page.even : @center-header $title;
endrule
# Data
data @main
transform @ingest;
include preface.txt;
include chapters/chapter*.txt;
enddata
data @index
include index.json;
enddata
# Transform
# Used for an initial transform if necessary
transform @ingest (text)
// JavaScript or other scripting language
// These aren't great examples, though
var response = text.replace(/CHAPTER/, "\n\nChapter");
response = response.replace(/\wteh\w/, "the");
return response;
endtransform
# Styles
# I don't have an example yet of how to use this, but imagine
# something ala InDesign or CSS
style @heading1
font Warnock Pro;
size 18/24pt;
onum;
-smcp; # turn off small caps
space-before 1.24em;
space-after 1.24em;
endstyle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment