TiCL
Didier Verna
Introduction
Programmatic
Textual
Extensions
Conclusion
TiCL: the prototype
Star T
E
X: the Next Generation (Season 2)
Didier Verna
didier@lrde.epita.fr
@didierverna
facebook/didier.verna
http://www.lrde.epita.fr/˜didier
TUG 2013, October 23 – 26
1/23
TiCL
Didier Verna
Introduction
Programmatic
Textual
Extensions
Conclusion
T
E
X
The [final] frontier.
These are the voyages,
Of a software enterprise.
Its continuing mission:
To explore new tokens,
To seek out a new life,
New forms of implementation. . .
2/23
TiCL
Didier Verna
Introduction
Programmatic
Textual
Extensions
Conclusion
A modernized T
E
X
Previously, on Star T
E
X TNG. . .
T
E
X’s strength is in the quality of its typesetting, not in its
programmatic interface.
Keep the typesetting functionality but provide. . .
A more modern and consistent API
Real programming capabilities
Still simple to use (at least for simple things)
Extensibility / customizability
4/23
TiCL
Didier Verna
Introduction
Programmatic
Textual
Extensions
Conclusion
Fitness of Lisp
Previously, on Star T
E
X TNG. . .
Existing approaches are heterogeneous
What about a fully integrated approach ?
Industrial-scale general purpose language
Multi-paradigm
Highly optimizable
Pletora of libraries
Scripting / extension language
Highly dynamic
Highly reflexive
Easy to learn (no syntax)
5/23
TiCL
Didier Verna
Introduction
Programmatic
Textual
Extensions
Conclusion
TiCL: the prototype
Current architecture
6/23
TiCL
Didier Verna
Introduction
Programmatic
Textual
Extensions
Conclusion
This is where we start
Not very T
E
Xy. . .
cl-typesetting Hello World
( defun firstdocument (& key ( f i l e "/tmp/texput.pdf" ) )
( t t : withdocument ( )
( l e t ( ( c ont e n t ( t t : compile t e x t ( )
( t t : par agraph ( ) "This is some text." ) ) ) )
( t t : drawpages cont e n t )
(when p d f : page ( ty p e s et : f i na l i ze p a g e pd f : page ) )
( t t : writedocument f i l e ) ) ) )
8/23
TiCL
Didier Verna
Introduction
Programmatic
Textual
Extensions
Conclusion
L
A
T
E
X-like programmatic layer: step 1
Still full of Lisp idioms
Global variables:
*
title
*
,
*
author
*
etc.
Functions: document-class, make-title etc.
Note: keywords arguments
Macros: with-document, with-section etc.
9/23
TiCL
Didier Verna
Introduction
Programmatic
Textual
Extensions
Conclusion
L
A
T
E
X-like programmatic layer: step 2
Less full of Lisp idioms
Non lispy accessors (although for constants)
Non lispy function (macro) names
Raw symbols instead of keywords
for constant arguments
Requires a macro layer
Example
; ; Be for e :
( documentclass : a r t i c l e : paper : l e t t e r : pt 12)
; ; Af t e r :
( documentclass a r t i c l e : paper l e t t e r : p t 12 )
10/23
TiCL
Didier Verna
Introduction
Programmatic
Textual
Extensions
Conclusion
L
A
T
E
X-like programmatic layer: step 3
Even less full of Lisp idioms
Symbol macros
Turning 0-ary function calls into mere symbols
More non lispy function (macro) names
Example
; ; Be for e :
( ma k e t i tle )
( tableo f c o n tents )
; ; Af t e r :
m a k e t i t l e
t a b l e o f c o n t e n t s
11/23
TiCL
Didier Verna
Introduction
Programmatic
Textual
Extensions
Conclusion
L
A
T
E
X-like programmatic layer: step 4
Getting rid of some with-
*
idioms
A (par) command instead of the with-par macro
And the par symbol macro that goes with it.
Example
; ; Be for e :
( withpar "bla bla bla" )
( withpar "bla bla bla" )
; ; Af t e r :
"bla bla bla" pa r "bla bla bla"
12/23
TiCL
Didier Verna
Introduction
Programmatic
Textual
Extensions
Conclusion
L
A
T
E
X-like programmatic layer: step 5
Getting rid of some other with-
*
idioms
Standalone sectionning commands
Need to get rid of underlying macros
Require explicit state management
e.g. PDF outline levels
Example
; ; Be for e :
( wi t h se c t i o n "Title"
"bla bla bla" pa r
"bla bla bla")
; ; Af t e r :
( se c t i o n "Title" )
"bla bla bla" pa r
"bla bla bla"
13/23
TiCL
Didier Verna
Introduction
Programmatic
Textual
Extensions
Conclusion
L
A
T
E
X-like programmatic layer: step 6
The “empty lines” trick
Replacing par with empty lines in Lisp strings
Requires overriding cl-typesettings behavior
But that’s easy (it’s Lisp) !
Example
; ; Be for e :
( se c t i o n "Title" )
"bla bla bla" pa r
"bla bla bla")
; ; Af t e r :
( se c t i o n "Title" )
"bla bla bla
bla bla bla"
14/23
TiCL
Didier Verna
Introduction
Programmatic
Textual
Extensions
Conclusion
L
A
T
E
X-like programmatic layer: step 7
L
A
T
E
X-like named environments
When impossible to get rid of the macro layer
Syntax extension through (read-time) macro characters
Example
; ; Be for e :
( withdocument
"bla bla bla"
"bla bla bla")
; ; Af t e r :
{ begi n document }
"bla bla bla"
"bla bla bla"
{ end document }
15/23
TiCL
Didier Verna
Introduction
Programmatic
Textual
Extensions
Conclusion
L
A
T
E
X-like textual layer
The ultimate goal
Idea
Remain text-driven instead of program-driven
Convert automatically to the programmatic layer
Implementation
Use \ as an escape (to Lisp) character
Everything else is accumulated into Lisp strings
Example
; ; Be for e :
( se c t i o n "Lorem Ipsum")
"Lorem " ( t e x t bf "ipsum" ) " " ( t e x t i t "dolor" ) " sit amet, ...
;; After:
\(section "Lorem Ipsum")
Lorem \(textbf "ipsum") \(textit "d o l o r ") sit amet, ...
17/23
TiCL
Didier Verna
Introduction
Programmatic
Textual
Extensions
Conclusion
The merits of extensibility
By example
Rivers detection
Requires introspection (boxes internal representation)
But that’s easy (it’s Lisp, and OO) !
Implementation
New kind of box (subclass of vbox)
Collects content subject to rivers detection
Additional stroking method for this new box
User-level “rivers” environment
19/23
TiCL
Didier Verna
Introduction
Programmatic
Textual
Extensions
Conclusion
Conclusion
Last year: fitness of Lisp for a T
E
X implementation
This year: proof of concept
Remember the objectives ?
A more modern and consistent API
Real programming capabilities
Still simple to use (at least for simple things)
Extensibility / customizability
21/23
TiCL
Didier Verna
Introduction
Programmatic
Textual
Extensions
Conclusion
These were the voyages,
Of a software enterprise.
Its continuing mission:
To explore new tokens,
To seek out a new life,
New forms of implementation.
To \textbf{go},
Where no T
E
X has gone before!
22/23
TiCL
Didier Verna
Introduction
Programmatic
Textual
Extensions
Conclusion
Live long and prosper!
Questions?
23/23