summaryrefslogtreecommitdiff
path: root/tex/context
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context')
-rw-r--r--tex/context/interface/third/t-letterspace.xml70
-rw-r--r--tex/context/third/letterspace/t-letterspace.mkiv167
2 files changed, 237 insertions, 0 deletions
diff --git a/tex/context/interface/third/t-letterspace.xml b/tex/context/interface/third/t-letterspace.xml
new file mode 100644
index 0000000..bac1f3f
--- /dev/null
+++ b/tex/context/interface/third/t-letterspace.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+
+<cd:interface xmlns:cd="http://www.pragma-ade.com/commands"
+ name="context"
+ language="en"
+ version="2011-03-16T10:30:36+0100">
+
+ <cd:command name="setupletterspace" file="t-letterspace.mkiv">
+ <cd:sequence>
+ <cd:string value="setupletterspace"/>
+ </cd:sequence>
+ <cd:arguments>
+ <cd:keywords n="1" optional="yes">
+ <cd:constant type="cd:name"/>
+ </cd:keywords>
+ <cd:assignments n="2" list="yes" optional="no">
+ <cd:parameter name="factor">
+ <!-- Can’t inherit from “\setupcharacterkerning” because cont-en.xml
+ still lacks that entry. -->
+ <cd:constant type="cd:number" default=".125"/>
+ </cd:parameter>
+ <cd:parameter name="spaceskip">
+ <cd:constant type="cd:dimension" default=".33em"/>
+ </cd:parameter>
+ <cd:parameter name="suppresskern">
+ <cd:constant type="no" default="no"/>
+ <cd:constant type="yes"/>
+ </cd:parameter>
+ </cd:assignments>
+ </cd:arguments>
+ </cd:command>
+
+ <cd:command name="defineletterspace" file="t-letterspace.tex">
+ <cd:sequence>
+ <cd:string value="defineletterspace"/>
+ </cd:sequence>
+ <cd:arguments>
+ <cd:keywords n="1" optional="no">
+ <cd:constant type="cd:name"/>
+ </cd:keywords>
+ <cd:assignments n="2" list="yes" optional="yes">
+ <cd:inherit name="setupletterspace" n="2"/>
+ </cd:assignments>
+ </cd:arguments>
+ </cd:command>
+
+ <cd:command name="letterspace" generated="yes" file="t-letterspace.mkiv">
+ <cd:sequence>
+ <cd:variable value="letterspace"/>
+ </cd:sequence>
+ <cd:arguments>
+ <cd:assignments n="1" list="yes" optional="yes">
+ <cd:inherit name="setupletterspace"/>
+ </cd:assignments>
+ <cd:content n="2" optional="yes"/>
+ </cd:arguments>
+ </cd:command>
+
+ <cd:command name="letterspace" generated="yes" type="environment" file="t-letterspace.mkiv">
+ <cd:sequence>
+ <cd:variable value="letterspace"/>
+ </cd:sequence>
+ <cd:arguments>
+ <cd:assignments n="1" list="yes" optional="yes">
+ <cd:inherit name="setupletterspace"/>
+ </cd:assignments>
+ </cd:arguments>
+ </cd:command>
+
+</cd:interface>
diff --git a/tex/context/third/letterspace/t-letterspace.mkiv b/tex/context/third/letterspace/t-letterspace.mkiv
new file mode 100644
index 0000000..ce3f026
--- /dev/null
+++ b/tex/context/third/letterspace/t-letterspace.mkiv
@@ -0,0 +1,167 @@
+%D \module [
+%D file=t-letterspace,
+%D version=2011-03-15T12:59:48+0100 or later,
+%D title=\CONTEXT\ User Module,
+%D subtitle=Letterspacing commands,
+%D author=Philipp Gesang,
+%D date=\currentdate,
+%D copyright=Philipp Gesang,
+%D license=2-clause BSD,
+%D ]
+
+%C Read the license conditions in the file \type{COPYING}.
+
+
+
+\writestatus{loading}{ConTeXt User Module / Letterspace}
+
+\startmodule [letterspace]
+
+\startinterface all
+ \setinterfacevariable {letterspace} {letterspace}
+ \setinterfacevariable {factor} {factor}
+ \setinterfacevariable {spaceskip} {spaceskip}
+ \setinterfacevariable {suppresskern}{suppresskern}
+\stopinterface
+
+\unprotect
+
+\definenamespace [\v!letterspace] [
+ command=yes,
+ comment=Letterspace module,
+ name=\v!letterspace,
+ \s!parent=\v!letterspace,
+ setup=list,
+ style=no,
+ type=module,
+ version=hg-rev:3+,
+]
+
+%D \macros
+%D {letterspace}
+%D
+%D \useURL [wschuster] [https://bitbucket.org/wolfs/] [] [Wolfgang Schuster]
+%D \from[wschuster]’s {\em fancybreak} and {\em annotation}
+%D modules served as the primary source for the following code.
+%D You’ll have to thank him if it works and blame me if it doesn’t.
+
+\appendtoks
+ \setuevalue{\currentletterspace }{\doletterspace[\currentletterspace]}%
+ \setuevalue{\e!start\currentletterspace}{\dostartletterspace[\currentletterspace]}%
+ \setuevalue{\e!stop \currentletterspace}{\dostopletterspace}%
+\to \everydefineletterspace
+
+\definecharacterkerning [letterspace:current]
+
+\unexpanded\def\doletterspace[#1]{%
+ \edef\currentletterspace{#1}%
+ \dosingleempty\dodoletterspace%
+}
+
+\def\dodoletterspace[#1]{%
+ \iffirstargument
+ \doifassignment{#1}{%
+ \setupletterspace[\currentletterspace][#1]%
+ }%
+ \fi
+ \dododoletterspace%
+}
+
+\definefontfeature [letterspace:kerning] [kern=yes]
+\def\letterspace_truevalues{true,yep,yes}
+
+\def\dododoletterspace#1{%
+ \def\currentobject{#1}%
+ \dontleavehmode
+ \setupcharacterkerning[letterspace:current][factor=\letterspaceparameter{factor}]%
+ \def\letterspace_setstuff{%
+ \setcharacterkerning[letterspace:current]%
+ \advance \spaceskip \letterspaceparameter{spaceskip}%
+ \advance \xspaceskip \letterspaceparameter{spaceskip}%
+ \doifinset{\letterspaceparameter{suppresskern}}{\letterspace_truevalues}{%
+ \subtractfontfeaturefromfont{letterspace:kerning}%
+ }%
+ }%
+ \ifhmode\ifnum\lastnodetype=\@@gluenode
+ \unskip{\letterspace_setstuff\ }%
+ \fi
+ \fi%
+ {\letterspace_setstuff\currentobject}%
+ \doifnextspace{%
+ {\letterspace_setstuff\ }%
+ \gobblespacetokens%
+ }%
+}
+
+%D This is a partial ripoff of a couple of macros from
+%D \type{syst-aux.mkiv}.
+%D \useURL [flet] [http://www.tug.org/TUGboat/Articles/tb09-3/tb22bechtolsheim.pdf] [] [\type{futurelet}]
+%D Very helpful for further understanding of what’s exactly going
+%D on: Stephan von Bechtolsheim’s tutorial on \from[flet].
+%D
+%D In short: the trick is checking whether the token following
+%D the command is a space, that is: whether it expands to
+%D \type{\blankspace}. If the test succeeds, a space will be
+%D added that has the correct parameters and all space tokens
+%D following the command will be gobbled. Otherwise -- the next
+%D token being anything else -- \type{\letterspace} will proceed
+%D without changing anything.
+
+\def\doifnextspace#1{%
+ \def\!!string{#1}%
+ \futurelet\nexttoken\inspectnexttoken%
+}
+
+\def\inspectnexttoken{%
+ \ifx\nexttoken\blankspace
+ \@EA\!!string
+ \fi%
+}
+
+%D \macros
+%D {startletterspace,stopletterspace}
+%D
+%D These rely even more shamelessly on \from[wschuster]’s code
+%D from the {\em fancybreak} module.
+%D
+%D The \type{\[start|stop]letterspace} environment is provided
+%D for sake of completeness.
+
+\unexpanded\def\dostartletterspace[#1]{%
+ \edef\currentletterspace{#1}%
+ \dosingleempty\dodostartletterspace%
+}
+
+\def\dodostartletterspace[#1]{%
+ \iffirstargument
+ \setupletterspace[\currentletterspace][#1]%
+ \fi
+ \dododoletterspace\bgroup%
+}
+
+\let\dostopletterspace\egroup
+
+%D \macros
+%D {setupletterspace}
+%D
+%D Initial setup.
+%D The factor by which the {\em letter space} (i.e. space between
+%D glyphs) will be increased is specified via the
+%D \type{factor} key.
+%D Additionally, it is wise with respect to legibility to enlarge
+%D the {\em interword space} as well. That is what the
+%D \type{spaceskip} key is for. The {\em spaceskip} should be an
+%D ordinary dimension.
+
+\setupletterspace [
+ \v!factor=.125,
+ \v!spaceskip=.5em,
+ \v!suppresskern=false,
+]
+
+\defineletterspace[\v!letterspace]
+
+\protect \stopmodule \endinput
+
+% vim:ft=context:sw=2:ts=2
+