summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore18
-rw-r--r--README5
-rw-r--r--all.do1
-rw-r--r--blog.cabal23
-rw-r--r--blog.nix17
-rwxr-xr-xbuild/extract-title.hs25
-rwxr-xr-xbuild/generate-rss.hs88
-rw-r--r--build/preamble.tex259
-rw-r--r--build/preview/preview.dtx1872
-rw-r--r--build/preview/preview.ins44
-rw-r--r--build/preview/preview.sty.do4
-rwxr-xr-xbuild/tex-filter.hs61
-rw-r--r--clean.do4
-rw-r--r--default.html.do15
-rw-r--r--default.nix22
-rw-r--r--default.svg.do28
-rwxr-xr-xdo177
-rw-r--r--getopts_long.sh701
-rw-r--r--htdocs.do3
-rw-r--r--index.md.do27
-rwxr-xr-xlists.sh66
-rwxr-xr-xposts.sh41
-rw-r--r--rss/default.rss.do4
-rw-r--r--src/Site.hs16
-rw-r--r--style.css40
-rw-r--r--sync.do2
-rw-r--r--templates/default.html (renamed from build/template.html5)0
27 files changed, 71 insertions, 3492 deletions
diff --git a/.gitignore b/.gitignore
index 16e0d46..c4a847d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,17 +1 @@
1.do_built* /result
2build/preview/*
3!build/preview/preview.dtx
4!build/preview/preview.ins
5!build/preview/preview.sty.do
6htdocs
7nginx
8
9*.html
10*.rss
11index.md
12lists/*.md
13lists/*/preview
14tex/
15
16cabal.sandbox.config
17.cabal-sandbox/ \ No newline at end of file
diff --git a/README b/README
deleted file mode 100644
index 13b8af0..0000000
--- a/README
+++ /dev/null
@@ -1,5 +0,0 @@
1This is my personal take on a static blogging system. I make integral
2use of djb's redo (for more information see https://github.com/apenwarr/redo).
3However, the whole thing is a pretty big mess.
4
5Caveat lector. \ No newline at end of file
diff --git a/all.do b/all.do
deleted file mode 100644
index 9facf1a..0000000
--- a/all.do
+++ /dev/null
@@ -1 +0,0 @@
1redo-ifchange index.html
diff --git a/blog.cabal b/blog.cabal
new file mode 100644
index 0000000..b8daa19
--- /dev/null
+++ b/blog.cabal
@@ -0,0 +1,23 @@
1-- Initial beuteltier.cabal generated by cabal init. For further
2-- documentation, see http://haskell.org/cabal/users-guide/
3
4name: dirty-haskell
5version: 0.0.0
6-- synopsis:
7-- description:
8homepage: git://git.yggdrasil.li/dirty-haskell.org
9-- license: PublicDomain
10-- license-file: LICENSE
11author: Gregor Kleen
12maintainer: aethoago@141.li
13copyright: N/A
14category: Web
15build-type: Simple
16-- extra-source-files:
17cabal-version: >=1.10
18
19executable site
20 hs-source-dirs: src
21 main-is: Site.hs
22 build-depends: base >=4.7 && <4.8
23 , hakyll >=4.6 && <5
diff --git a/blog.nix b/blog.nix
new file mode 100644
index 0000000..52e23ca
--- /dev/null
+++ b/blog.nix
@@ -0,0 +1,17 @@
1# This file was auto-generated by cabal2nix. Please do NOT edit manually!
2
3{ mkDerivation, stdenv
4, hakyll
5}:
6
7mkDerivation {
8 pname = "dirty-haskell";
9 version = "0.0.0";
10 src = ./.;
11 isExecutable = true;
12 isLibrary = false;
13 buildDepends = [
14 hakyll
15 ];
16 license = stdenv.lib.licenses.publicDomain;
17}
diff --git a/build/extract-title.hs b/build/extract-title.hs
deleted file mode 100755
index 6964d26..0000000
--- a/build/extract-title.hs
+++ /dev/null
@@ -1,25 +0,0 @@
1#!/usr/bin/env runhaskell
2
3-- import Text.Pandoc.Pretty
4-- import Text.Pandoc.JSON
5import Text.Pandoc.Pretty
6import Text.Pandoc.JSON
7import qualified Text.Pandoc.Walk as W
8import System.IO
9import qualified Data.Aeson as A
10import qualified Data.ByteString.Lazy as BL
11
12extract_title :: Pandoc -> String
13extract_title (Pandoc m _) = do
14 title <- render Nothing $ cat $ map pretty (docTitle m)
15 return title
16 where pretty :: Inline -> Doc
17 pretty (Str s) = text s
18 pretty Space = space
19 pretty _ = empty
20
21main :: IO ()
22main = do
23 input <- BL.getContents
24 let title = (W.query extract_title :: Pandoc -> String) . either error id . A.eitherDecode' $ input
25 putStrLn title
diff --git a/build/generate-rss.hs b/build/generate-rss.hs
deleted file mode 100755
index 2263ba8..0000000
--- a/build/generate-rss.hs
+++ /dev/null
@@ -1,88 +0,0 @@
1#!/usr/bin/env runhaskell
2
3import System.Environment (getArgs)
4import qualified Control.Monad.State as S
5import Control.Monad (sequence)
6
7import Text.Feed.Constructor
8import Text.Feed.Util
9import Text.Feed.Export
10import Text.Feed.Types
11
12import Text.Pandoc
13import Text.Pandoc.Pretty
14
15import qualified System.Time as T
16import qualified System.Posix.Files as F
17import qualified Text.XML.Light.Output as X
18import qualified System.FilePath as FP
19import System.Posix.Types
20
21import Data.Maybe (fromMaybe)
22import Data.List (dropWhileEnd, isSuffixOf)
23
24type FeedState = (Feed, Maybe T.ClockTime)
25
26feedKind = RSSKind $ Just "2.0"
27
28baseurl = "http://dirty-haskell.org"
29
30description = "dirty-haskell.org — a blog"
31
32mkUrl' :: FilePath -> String
33mkUrl' path = (++) (baseurl ++ "/posts/") $ (flip FP.replaceExtension) "html" $ FP.takeFileName path
34
35
36extract_title :: Pandoc -> String
37extract_title (Pandoc m _) = do
38 title <- render Nothing $ cat $ map pretty (docTitle m)
39 return title
40 where pretty :: Inline -> Doc
41 pretty (Str s) = text s
42 pretty Space = space
43 pretty _ = empty
44
45main :: IO ()
46main = do
47 (title:entries) <- getArgs
48 currentTime <- T.getClockTime
49 let feed = foldl1 (.)
50 [ withFeedDescription description
51 , withFeedHome baseurl
52 , withFeedTitle title
53 ] $ newFeed feedKind
54 (populatedFeed, itemTime) <- S.execStateT (sequence $ map addItem' entries) (feed, Nothing)
55 let populatedFeed' = withFeedPubDate (toFeedDateString feedKind $ fromMaybe currentTime itemTime) $ withFeedLastUpdate (toFeedDateString feedKind currentTime) $ populatedFeed
56 putStrLn $ X.ppElement $ xmlFeed populatedFeed'
57
58addItem' :: FilePath -> S.StateT FeedState IO ()
59addItem' mdFile = do
60 url <- S.liftIO $ mkUrl mdFile
61 fileStatus <- S.liftIO $ F.getSymbolicLinkStatus mdFile
62 fileContents <- S.liftIO $ readFile mdFile
63 let title = extract_title $ document
64 contents = writeAsciiDoc def document
65 document = readMarkdown def fileContents
66 (feed, time) <- S.get
67 let fileTime = maximum ([F.modificationTime, F.statusChangeTime] <-> fileStatus) :: System.Posix.Types.EpochTime
68 fileTime' = T.TOD (toInteger $ fromEnum fileTime) 0
69 let item = foldl1 (.)
70 [ withItemTitle title
71 , withItemLink url
72 , withItemId True url
73 , withItemDate $ toFeedDateString feedKind fileTime'
74 , withItemDescription contents
75 ] $ newItem feedKind :: Item
76 S.put (addItem item feed, if (Just fileTime' > time) then Just fileTime' else time)
77
78mkUrl :: FilePath -> IO String
79mkUrl link = do
80 status <- F.getSymbolicLinkStatus link
81 if F.isSymbolicLink status then
82 do target <- F.readSymbolicLink link
83 mkUrl $ FP.combine (FP.takeDirectory link) target
84 else
85 return $ mkUrl' link
86(<->) :: [(a -> b)] -> a -> [b]
87[] <-> _ = []
88(f:fs) <-> x = (f x:fs <-> x)
diff --git a/build/preamble.tex b/build/preamble.tex
deleted file mode 100644
index cf3623b..0000000
--- a/build/preamble.tex
+++ /dev/null
@@ -1,259 +0,0 @@
1\documentclass[14pt,preview,border=1pt,class=extarticle]{standalone}
2
3\usepackage{amssymb}
4\usepackage{amsmath}
5\usepackage{etoolbox}
6\usepackage{xspace}
7\usepackage{mathrsfs}
8\usepackage{xifthen}
9
10\usepackage{tikz}
11\usetikzlibrary{arrows,decorations.markings,chains,calc,matrix}
12\usepackage{tikz-cd}
13\tikzset{>=cm to}
14
15\usepackage{mathtools}
16
17\undef\Re
18\undef\Im
19
20\DeclareMathOperator{\colim}{\textnormal{colim}}
21\DeclareMathOperator{\Spec}{\textnormal{Spec}}
22\DeclareMathOperator{\im}{\textnormal{im}}
23\DeclareMathOperator{\Sing}{\textnormal{Sing}}
24\DeclareMathOperator{\Map}{\textnormal{Map}}
25\DeclareMathOperator{\InnHom}{\textnormal{\textbf{Hom}}}
26\DeclareMathOperator{\Hom}{\textnormal{Hom}}
27\undef\hom
28\DeclareMathOperator{\hom}{\textnormal{hom}}
29\DeclareMathOperator{\nerve}{\textnormal{N}}
30\DeclareMathOperator{\simpnerve}{\textnormal{sN}}
31\DeclareMathOperator{\core}{\textnormal{Core}}
32\DeclareMathOperator{\id}{\textnormal{id}}
33\undef\lim
34\DeclareMathOperator{\lim}{\textnormal{lim}}
35\DeclareMathOperator{\Op}{\textnormal{op}}
36\DeclareMathOperator{\yon}{\textnormal{y}}
37\DeclareMathOperator{\HomL}{\textnormal{\textbf{Hom}}^{\textnormal{L}}}
38\DeclareMathOperator{\sk}{\textnormal{sk}}
39\DeclareMathOperator{\cosk}{\textnormal{cosk}}
40\DeclareMathOperator{\thom}{\textnormal{Th}}
41\DeclareMathOperator{\Bl}{\textnormal{Bl}}
42\DeclareMathOperator{\Stab}{\textnormal{Stab}}
43\DeclareMathOperator{\Grp}{\textnormal{\textsf{Grp}}}
44\DeclareMathOperator{\Set}{\textnormal{\textsf{Set}}}
45
46\newcommand*{\alg}[1]{\ensuremath{\overline{#1}}\xspace}
47\newcommand*{\sep}[1]{\ensuremath{#1^{\textnormal{sep}}}\xspace}
48\newcommand*{\ab}[1]{\ensuremath{#1^{\textnormal{ab}}}\xspace}
49\newcommand*{\units}[1]{\ensuremath{#1^\times}\xspace}
50\newcommand*{\lapl}{\Delta}
51\newcommand*{\grad}{\nabla}
52\newcommand*{\op}[1]{\ensuremath{#1^{\textnormal{op}}}\xspace}
53\newcommand*{\codiag}[1]{\ensuremath{\nabla\mkern-3mu_{#1}}\xspace}
54\newcommand*{\diag}[1]{\ensuremath{\Delta_{#1}}\xspace}
55
56\newcommand*{\cech}{\v{C}ech\xspace}
57\newcommand*{\mc}{\operatorname{\textnormal{\v{C}}}}
58
59\newcommand*{\normal}{\lhd}
60\newcommand*{\isom}{\cong}
61\newcommand*{\homot}{\sim}
62\newcommand*{\cequiv}{\simeq}
63
64\makeatletter
65\let\@oldsubset=\subset
66\def\@subsethelper#1#2{\mathrel{\raisebox{.5pt}{$#1\@oldsubset$}}\xspace}
67\DeclareRobustCommand*{\subset}{\mathpalette\@subsethelper\relax}
68
69\let\@oldotimes=\otimes
70\def\@otimeshelper#1#2{\mathrel{\raisebox{.5pt}{$#1\@oldotimes$}}\xspace}
71\DeclareRobustCommand*{\otimes}{\mathpalette\@otimeshelper\relax}
72\makeatother
73
74\tikzset{/tikz/commutative diagrams/arrows={thin}}
75
76\makeatletter
77\newbox\@xrat
78\renewcommand*{\xrightarrow}[2][-cm to]{%
79 \setbox\@xrat=\hbox{\ensuremath{\scriptstyle #2}}
80 \pgfmathsetlengthmacro{\@xratlen}{max(1.6em,\wd\@xrat+.6em)}
81 \pgfmathsetlengthmacro{\@xratinnersep}{.5ex-\dp\@xrat}
82 \mathrel{\tikz [#1,baseline=-.6ex]
83 \draw (0,0) -- node[auto,inner sep=\@xratinnersep] {\box\@xrat} (\@xratlen,0) ;}}
84\renewcommand*{\xleftarrow}[2][cm to-]{%
85 \setbox\@xrat=\hbox{\ensuremath{\scriptstyle #2}}
86 \pgfmathsetlengthmacro{\@xratlen}{max(1.6em,\wd\@xrat+.6em)}
87 \pgfmathsetlengthmacro{\@xratinnersep}{.5ex-\dp\@xrat}
88 \mathrel{\tikz [#1,baseline=-.6ex]
89 \draw (0,0) -- node[auto,inner sep=\@xratinnersep] {\box\@xrat} (\@xratlen,0) ;}}
90\newcommand*{\xrightarrowb}[2][-cm to]{%
91 \setbox\@xrat=\hbox{\ensuremath{\scriptstyle #2}}
92 \pgfmathsetlengthmacro{\@xratlen}{max(1.6em,\wd\@xrat+.6em)}
93 \pgfmathsetlengthmacro{\@xratinnersep}{.5ex}
94 \mathrel{\tikz [#1,baseline=-.6ex]
95 \draw (0,0) -- node[auto,inner sep=\@xratinnersep] {\box\@xrat} (\@xratlen,0) ;}}
96\newcommand*{\xleftarrowb}[2][cm to-]{%
97 \setbox\@xrat=\hbox{\ensuremath{\scriptstyle #2}}
98 \pgfmathsetlengthmacro{\@xratlen}{max(1.6em,\wd\@xrat+.6em)}
99 \pgfmathsetlengthmacro{\@xratinnersep}{.5ex}
100 \mathrel{\tikz [#1,baseline=-.6ex]
101 \draw (0,0) -- node[auto,inner sep=\@xratinnersep] {\box\@xrat} (\@xratlen,0) ;}}
102
103\pgfarrowsdeclare{my right hook}{my right hook}
104{
105\arrowsize=0.2pt
106\advance\arrowsize by .5\pgflinewidth
107\pgfarrowsleftextend{-.5\pgflinewidth}
108\pgfarrowsrightextend{3.5\arrowsize+.5\pgflinewidth}
109}
110{
111\arrowsize=0.2pt
112\advance\arrowsize by .5\pgflinewidth
113\pgfsetdash{}{0pt} % do not dash
114\pgfsetroundjoin % fix join
115\pgfsetroundcap % fix cap
116\pgfpathmoveto{\pgfpoint{0\arrowsize}{-7\arrowsize}}
117\pgfpatharc{-90}{90}{3.5\arrowsize}
118\pgfusepathqstroke
119}
120
121\tikzset{%
122 iso/.style={above,sloped,inner sep=0},
123 iso'/.style={below,sloped,inner sep=0},
124 to/.style={-cm to},
125 onto/.style={-cm double to},
126 into/.style={my right hook-cm to},
127 mapsto/.style={|-cm to},
128 clim/.style={decoration={markings,
129 mark=at position#1 with {\draw[-] (0,-3\pgflinewidth) -- (0,3\pgflinewidth);}},
130 postaction=decorate},
131 clim/.default=0.5,
132 opim/.style={decoration={markings,
133 mark=at position#1 with {\draw[-] circle(3\pgflinewidth);}},
134 postaction=decorate},
135 opim/.default=0.5
136}
137
138\newcommand*\@tikzto[2]{\mathrel{\begin{tikzpicture}[baseline]%
139 \draw[to,line width={#2\pgflinewidth},scale=#1](0,.55ex) -- (1.6em,.55ex);%
140 \end{tikzpicture}}}
141
142\newcommand*\@tikzcto[2]{\mathrel{\begin{tikzpicture}[baseline]%
143 \draw[to,line width={#2\pgflinewidth},scale=#1](0,.55ex) -- (0.8em,.55ex);%
144 \end{tikzpicture}}}
145
146\newcommand*\@tikzonto[2]{\mathrel{\begin{tikzpicture}[baseline]%
147 \draw[onto,line width={#2\pgflinewidth},scale=#1](0,.55ex) -- (1.6em,.55ex);%
148 \end{tikzpicture}}}
149
150\newcommand*\@tikzinto[2]{\mathrel{\begin{tikzpicture}[baseline]%
151 \draw[into,line width={#2\pgflinewidth},scale=#1](0,.55ex) -- (1.6em,.55ex);%
152 \end{tikzpicture}}}
153
154\newcommand*\@tikzclim[2]{\mathrel{\begin{tikzpicture}[baseline]%
155 \draw[into,clim,line width={#2\pgflinewidth},scale=#1](0,.55ex) -- (1.6em,.55ex);%
156 \end{tikzpicture}}}
157
158\newcommand*\@tikzopim[2]{\mathrel{\begin{tikzpicture}[baseline]%
159 \draw[into,opim,line width={#2\pgflinewidth},scale=#1](0,.55ex) -- (1.6em,.55ex);%
160 \end{tikzpicture}}}
161
162\newcommand*\@tikzmapsto[2]{\mathrel{\begin{tikzpicture}[baseline]%
163 \draw[mapsto,line width={#2\pgflinewidth},scale=#1](0,.55ex) -- (1.6em,.55ex);%
164 \end{tikzpicture}}}
165
166\newcommand*\@tikziso[4]{\mathrel{\begin{tikzpicture}[baseline]%
167 \draw[to,line width={#2\pgflinewidth},scale=#1](0,.55ex) -- node[iso,pos=0.47,inner sep=#4]{$#3\sim$} (1.6em,.55ex);%
168 \end{tikzpicture}}}
169
170\newcommand*\tikzto{\mathchoice{\@tikzto{1.0}{1}}{\@tikzto{1.0}{1}}{\@tikzcto{0.8}{0.9}}{\@tikzcto{0.6}{0.75}}}
171\newcommand*\tikzcto{\mathchoice{\@tikzcto{1.0}{1}}{\@tikzcto{1.0}{1}}{\@tikzcto{0.8}{0.9}}{\@tikzcto{0.6}{0.75}}}
172\newcommand*\tikzonto{\mathchoice{\@tikzonto{1.0}{1}}{\@tikzonto{1.0}{1}}{\@tikzonto{0.8}{0.9}}{\@tikzonto{0.6}{0.75}}}
173\newcommand*\tikzinto{\mathchoice{\@tikzinto{1.0}{1}}{\@tikzinto{1.0}{1}}{\@tikzinto{0.8}{0.9}}{\@tikzinto{0.6}{0.75}}}
174\newcommand*\tikzclim{\mathchoice{\@tikzclim{1.0}{1}}{\@tikzclim{1.0}{1}}{\@tikzclim{0.8}{0.9}}{\@tikzclim{0.6}{0.75}}}
175\newcommand*\tikzopim{\mathchoice{\@tikzopim{1.0}{1}}{\@tikzopim{1.0}{1}}{\@tikzopim{0.8}{0.9}}{\@tikzopim{0.6}{0.75}}}
176\newcommand*\tikzmapsto{\mathchoice{\@tikzmapsto{1.0}{1}}{\@tikzmapsto{1.0}{1}}{\@tikzmapsto{0.8}{0.9}}{\@tikzmapsto{0.6}{0.75}}}
177\newcommand*\tikziso{\mathchoice{\@tikziso{1.0}{1}{\displaystyle}{0pt}}%
178 {\@tikziso{1.0}{1}{\textstyle}{0pt}}%
179 {\@tikziso{0.8}{0.9}{\scriptstyle}{0pt}}%
180 {\@tikziso{0.67}{0.8}{\scriptscriptstyle}{0.15ex}}}
181\makeatother
182
183\renewcommand*{\to}[1][]{\ifthenelse{\isempty{#1}}{\tikzto}{\xrightarrowb{#1}}}
184\newcommand*{\cto}{\ensuremath{\tikzcto}}
185\newcommand*{\into}[1][]{\ifthenelse{\isempty{#1}}{\tikzinto}{\xrightarrowb[into]{#1}}}
186\newcommand*{\onto}[1][]{\ifthenelse{\isempty{#1}}{\tikzonto}{\xrightarrowb[onto]{#1}}}
187\newcommand*{\clim}{\tikzclim}
188\newcommand*{\opim}{\tikzopim}
189
190\newcommand*{\iso}{\tikziso}
191
192\renewcommand*{\mapsto}{\tikzmapsto}
193
194\newcommand*{\ca}[1]{\ensuremath{\mathscr{#1}}\xspace}
195\renewcommand*{\cal}[1]{\ensuremath{\mathcal{#1}}\xspace}
196\newcommand*{\f}[1]{\ensuremath{\mathfrak{#1}}\xspace}
197
198\newcommand{\cl}[2][0]{{}\mkern#1mu\overline{\mkern-#1mu#2}}
199\newcommand*{\Int}[1]{\ensuremath{#1^\circ}\xspace}
200
201\newcommand*{\infcat}[1][1]{\((\infty,#1)\)–category\xspace}
202\newcommand*{\linfcat}{\(\infty\)–category\xspace}
203\newcommand*{\infcats}[1][1]{\((\infty,#1)\)–categories\xspace}
204\newcommand*{\linfcats}{\(\infty\)–categories\xspace}
205\newcommand*{\Cat}{\textnormal{\textsf{Cat}}}
206\newcommand*{\spc}{\textnormal{\textbf{Spc}}}
207\newcommand*{\ICat}{\textnormal{\textbf{Cat}}}
208\newcommand*{\infpshv}{\operatorname{\textnormal{\textbf{PShv}}}}
209\newcommand*{\infshv}{\operatorname{\textnormal{\textbf{Sh}}}}
210\newcommand*{\hypshv}{\operatorname{\widehat{\textnormal{\textbf{Sh}}}}}
211\newcommand*{\hyp}[1][]{\operatorname{\ca H}^{#1}\mkern-2mu}
212\newcommand*{\phyp}[1][]{\operatorname{\ca H}^{#1}_{\bullet}\mkern-2mu}
213\newcommand*{\sh}{\operatorname{\ca{SH}}}
214\newcommand*{\shv}{\operatorname{\textnormal{\textsf{Shv}}}}
215\newcommand*{\pshv}{\operatorname{\textnormal{\textsf{PShv}}}}
216\newcommand*{\Aff}{\operatorname{\textnormal{\textsf{Aff}}}}
217\newcommand*{\Ring}{\operatorname{\textnormal{\textsf{Ring}}}}
218\newcommand*{\Alg}{\operatorname{\textnormal{\textsf{Alg}}}}
219\newcommand*{\Disc}{\operatorname{\textnormal{\textsf{Disc}}}}
220\newcommand*{\mfd}{\operatorname{\textnormal{\textsf{Mfd}}}}
221\newcommand*{\sm}[1][k]{\mathop{\textnormal{\textsf{Sm}}/#1}}
222\newcommand*{\Simp}{\mathbf{\Delta}}
223\newcommand*{\sset}{\operatorname{\textnormal{\textsf{sSet}}}}
224\newcommand*{\ssetQ}{\operatorname{\textnormal{\textsf{sSet}}_{\textnormal{\textsf{Q}}}}}
225\newcommand*{\ssetJ}{\operatorname{\textnormal{\textsf{sSet}}_{\textnormal{\textsf{J}}}}}
226\newcommand*{\Top}{\operatorname{\textnormal{\textsf{Top}}}}
227\newcommand*{\qcat}{\operatorname{\textnormal{\textsf{qCat}}_{2}}}
228\newcommand*{\Fin}{\operatorname{\textnormal{\textsf{Fin}}_{*}}}
229\newcommand*{\tang}[1]{\textnormal{T}\mkern-2mu_{#1}}
230\newcommand*{\dual}[1]{\textnormal{D}#1}
231\newcommand*{\sch}[1][k]{\mathop{\textnormal{\textsf{Sch}}/#1}}
232
233\def\<#1>{\left\langle #1 \right\rangle}
234
235\newcommand{\dd}[1][]{%
236 \mathrm{d}%
237 \if\relax\detokenize{#1}\relax%
238 \else%
239 ^{#1}\mkern-1.5mu%
240 \fi%
241}
242
243\newcommand{\Diff}[1][]{%
244 \mathrm{D}%
245 \if\relax\detokenize{#1}\relax%
246 \else%
247 ^{#1}\m
248 kern-1.5mu%
249 \fi%
250}
251
252\newcommand{\ddd}[1][]{%
253 \mathop{}\!\dd[#1]%
254}
255
256\undef\AA
257\undef\SS
258\renewcommand*{\do}[1]{\expandafter\def\csname#1#1\endcsname{\ensuremath{\mathbb{#1}}\xspace}}
259\docsvlist{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}
diff --git a/build/preview/preview.dtx b/build/preview/preview.dtx
deleted file mode 100644
index 0675c27..0000000
--- a/build/preview/preview.dtx
+++ /dev/null
@@ -1,1872 +0,0 @@
1% \iffalse
2%% The preview style for extracting previews from LaTeX documents.
3%% Developed as part of AUCTeX <URL:http://www.gnu.org/software/auctex>.
4%
5% Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006,
6% 2010 Free Software Foundation
7%
8% This program is free software; you can redistribute it and/or modify
9% it under the terms of the GNU General Public License as published by
10% the Free Software Foundation; either version 3 of the License, or
11% (at your option) any later version.
12%
13% This program is distributed in the hope that it will be useful,
14% but WITHOUT ANY WARRANTY; without even the implied warranty of
15% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16% GNU General Public License for more details.
17%
18% You should have received a copy of the GNU General Public License
19% along with this program; if not, write to the
20% Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21% Boston, MA 02110-1301 USA
22% \fi
23% \CheckSum{1758}
24% \GetFileInfo{preview.sty}
25% \date{\filedate}
26% \author{David Kastrup\thanks{\texttt{dak@gnu.org}}}
27% \title{The \texttt{preview} Package for \LaTeX\\Version \fileversion}
28% \maketitle
29% \section{Introduction}
30% The main purpose of this package is the extraction of certain
31% environments (most notably displayed formulas) from \LaTeX\ sources
32% as graphics. This works with DVI files postprocessed by either
33% Dvips and Ghostscript or dvipng, but it also works when you are
34% using PDF\TeX\ for generating PDF files (usually also postprocessed
35% by Ghostscript).
36%
37% Current uses of the package include the \previewlatex\ package for
38% WYSIWYG functionality in the AUC\TeX\ editing environment,
39% generation of previews in LyX, as part of the operation of the
40% ps4pdf package, the tbook XML system and some other tools.
41%
42% Producing EPS files with Dvips and its derivatives using the
43% \texttt{-E} option is not a good alternative: People make do by
44% fiddling around with |\thispagestyle{empty}| and hoping for the best
45% (namely, that the specified contents will indeed fit on single
46% pages), and then trying to guess the baseline of the resulting code
47% and stuff, but this is at best dissatisfactory. The preview package
48% provides an easy way to ensure that exactly one page per request
49% gets shipped, with a well-defined baseline and no page decorations.
50% While you still can use the preview package with the `classic'
51% \begin{quote}
52% |dvips -E -i|
53% \end{quote}
54% invocation, there are better ways available that don't rely on Dvips
55% not getting confused by PostScript specials.
56%
57% For most applications, you'll want to make use of the |tightpage|
58% option. This will embed the page dimensions into the PostScript or
59% PDF code, obliterating the need to use the |-E -i| options to Dvips.
60% You can then produce all image files with a single run of
61% Ghostscript from a single PDF or PostScript (as opposed to EPS)
62% file.
63%
64% Various options exist that will pass \TeX\ dimensions and other
65% information about the respective shipped out material (including
66% descender size) into the log file, where external applications might
67% make use of it.
68%
69% The possibility for generating a whole set of graphics with a single
70% run of Ghostscript (whether from \LaTeX\ or PDF\LaTeX) increases
71% both speed and robustness of applications. It is also feasible to
72% use dvipng on a DVI file with the options
73% \begin{quote}
74% |-picky -noghostscript|
75% \end{quote}
76% to omit generating any image file that requires Ghostscript, then
77% let a script generate all missing files using Dvips/Ghostscript.
78% This will usually speed up the process significantly.
79%
80% \section{Package options}
81% The package is included with the customary
82% \begin{quote}
83% |\usepackage|\oarg{options}|{preview}|
84% \end{quote}
85% You should usually load this package as the last one, since it
86% redefines several things that other packages may also provide.
87%
88% The following options are available:
89% \begin{description}
90% \item[|active|] is the most essential option. If this option is not
91% specified, the |preview| package will be inactive and the document
92% will be typeset as if the |preview| package were not loaded,
93% except that all declarations and environments defined by the
94% package are still legal but have no effect. This allows defining
95% previewing characteristics in your document, and only activating
96% them by calling \LaTeX\ as
97% \begin{quote}
98% \raggedright
99% |latex '\PassOptionsToPackage{active}{preview}| |\input|\marg{filename}|'|
100% \end{quote}
101% \item[|noconfig|] Usually the file |prdefault.cfg| gets loaded
102% whenever the |preview| package gets activated. |prdefault.cfg| is
103% supposed to contain definitions that can cater for otherwise bad
104% results, for example, if a certain document class would otherwise
105% lead to trouble. It also can be used to override any settings
106% made in this package, since it is loaded at the very end of it.
107% In addition, there may be configuration files specific for certain
108% |preview| options like |auctex| which have more immediate needs.
109% The |noconfig| option suppresses loading of those option files,
110% too.
111% \item[|psfixbb|] Dvips determines the bounding boxes from the
112% material in the DVI file it understands. Lots of PostScript
113% specials are not part of that. Since the \TeX\ boxes do not make
114% it into the DVI file, but merely characters, rules and specials
115% do, Dvips might include far too small areas. The option |psfixbb|
116% will include |/dev/null| as a graphic file in the ultimate upper
117% left and lower right corner of the previewed box. This will make
118% Dvips generate an appropriate bounding box.
119% \item[|dvips|] If this option is specified as a class option or to
120% other packages, several packages pass things like page size
121% information to Dvips, or cause crop marks or draft messages
122% written on pages. This seriously hampers the usability of
123% previews. If this option is specified, the changes will be undone
124% if possible.
125% \item[|pdftex|] If this option is set, PDF\TeX\ is assumed as the
126% output driver. This mainly affects the |tightpage| option.
127% \item[|xetex|] If this option is set, Xe\TeX\ is assumed as the
128% output driver. This mainly affects the |tightpage| option.
129% \item[|displaymath|] will make all displayed math environments
130% subject to preview processing. This will typically be the most
131% desired option.
132% \item[|floats|] will make all float objects subject to preview
133% processing. If you want to be more selective about what floats to
134% pass through to a preview, you should instead use the
135% \cmd{\PreviewSnarfEnvironment} command on the floats you want to
136% have previewed.
137% \item[|textmath|] will make all text math subject to previews.
138% Since math mode is used throughly inside of \LaTeX\ even for other
139% purposes, this works by redefining \cmd\(, \cmd\)
140% and |$| and the |math| environment (apparently some people use
141% that). Only occurences of these text math delimiters in later
142% loaded packages and in the main document will thus be affected.
143% \item[|graphics|] will subject all \cmd{\includegraphics} commands
144% to a preview.
145% \item[|sections|] will subject all section headers to a preview.
146% \item[|delayed|] will delay all activations and redefinitions the
147% |preview| package makes until |\||begin{document}|. The purpose
148% of this is to cater for documents which should be subjected to the
149% |preview| package without having been prepared for it. You can
150% process such documents with
151% \begin{quote}
152% |latex '\RequirePackage[active,delayed,|\meta{options}|]{preview}|
153% |\input|\marg{filename}|'|
154% \end{quote}
155% This relaxes the requirement to be loading the |preview| package
156% as last package.
157% \item[\meta{driver}] loads a special driver file
158% |pr|\meta{driver}|.def|. The remaining options are implemented
159% through the use of driver files.
160% \item[|auctex|] This driver will produce fake error messages at the
161% start and end of every preview environment that enable the Emacs
162% package \previewlatex\ in connection with AUC\TeX\ to pinpoint
163% the exact source location where the previews have originated.
164% Unfortunately, there is no other reliable means of passing the
165% current \TeX\ input position \emph{in} a line to external
166% programs. In order to make the parsing more robust, this option
167% also switches off quite a few diagnostics that could be
168% misinterpreted.
169%
170% You should not specify this option manually, since it will only be
171% needed by automated runs that want to parse the pseudo error
172% messages. Those runs will then use \cmd{\PassOptionsToPackage} in
173% order to effect the desired behaviour. In addition,
174% |prauctex.cfg| will get loaded unless inhibited by the |noconfig|
175% option. This caters for the most frequently encountered
176% problematic commands.
177% \item[|showlabels|] During the editing process, some people like to
178% see the label names in their equations, figures and the like. Now
179% if you are using Emacs for editing, and in particular
180% \previewlatex, I'd strongly recommend that you check out the
181% Ref\TeX\ package which pretty much obliterates the need for this
182% kind of functionality. If you still want it, standard \LaTeX\
183% provides it with the |showkeys| package, and there is also the
184% less encompassing |showlabels| package. Unfortunately, since
185% those go to some pain not to change the page layout and spacing,
186% they also don't change |preview|'s idea of the \TeX\ dimensions of
187% the involved boxes. So if you are using |preview| for determing
188% bounding boxes, those packages are mostly useless. The option
189% |showlabels| offers a substitute for them.
190% \item[|tightpage|] It is not uncommon to want to use the results of
191% |preview| as graphic images for some other application. One
192% possibility is to generate a flurry of EPS files with
193% \begin{quote}
194% |dvips -E -i -Pwww -o| \meta{outputfile}|.000| \meta{inputfile}
195% \end{quote}
196% However, in case those are to be processed further into graphic
197% image files by Ghostscript, this process is inefficient since all
198% of those files need to be processed one by one. In addition, it
199% is necessary to extract the bounding box comments from the EPS
200% files and convert them into page dimension parameters for
201% Ghostscript in order to avoid full-page graphics. This is not
202% even possible if you wanted to use Ghostscript in a~\emph{single}
203% run for generating the files from a single PostScript file, since
204% Dvips will in that case leave no bounding box information
205% anywhere.
206%
207% The solution is to use the |tightpage| option. That way a single
208% command line like
209% \begin{quote}
210% \raggedright
211% \texttt{gs -sDEVICE=png16m -dTextAlphaBits=4 -r300
212% -dGraphicsAlphaBits=4 -dSAFER -q -dNOPAUSE
213% -sOutputFile=\meta{outputfile}\%d.png \meta{inputfile}.ps}
214% \end{quote}
215% will be able to produce tight graphics from a single PostScript
216% file generated with Dvips \emph{without} use of the options
217% |-E -i|, in a single run.
218%
219% The |tightpage| option actually also works when using the |pdftex|
220% option and generating PDF files with PDF\TeX. The resulting PDF
221% file has separate page dimensions for every page and can directly
222% be converted with one run of Ghostscript into image files.
223%
224% If neither |dvips| or |pdftex| have been specified, the
225% corresponding option will get autodetected and invoked.
226%
227% If you need this in a batch environment where you don't want to
228% use |preview|'s automatic extraction facilities, no problem: just
229% don't use any of the extraction options, and wrap everything to be
230% previewed into |preview| environments. This is how LyX does its
231% math previews.
232%
233% If the pages under the |tightpage| option are just too tight, you
234% can adjust by setting the length |\PreviewBorder| to a different
235% value by using \cmd{\setlength}. The default value is
236% |0.50001bp|, which is half of a usual PostScript point, rounded
237% up. If you go below this value, the resulting page size may drop
238% below |1bp|, and Ghostscript does not seem to like that. If you
239% need finer control, you can adjust the bounding box dimensions
240% individually by changing the macro |\PreviewBbAdjust| with the
241% help of |\renewcommand|. Its default value is
242% \begin{quote}
243% \raggedright
244% |\newcommand| |\PreviewBbAdjust|
245% |{-\PreviewBorder| |-\PreviewBorder|
246% |\PreviewBorder| |\PreviewBorder}|
247% \end{quote}
248% This adjusts the left, lower, right and upper borders by the given
249% amount. The macro must contain 4~\TeX\ dimensions after another,
250% and you may not omit the units if you specify them explicitly
251% instead of by register. PostScript points have the unit~|bp|.
252% \item[|lyx|] This option is for the sake of LyX developers. It will
253% output a few diagnostics relevant for the sake of LyX' preview
254% functionality (at the time of writing, mostly implemented for math
255% insets, in versions of LyX starting with 1.3.0).
256% \item[|counters|] This writes out diagnostics at the start and the
257% end of previews. Only the counters changed since the last output
258% get written, and if no counters changed, nothing gets written at
259% all. The list consists of counter name and value, both enclosed
260% in |{}| braces, followed by a space. The last such pair is
261% followed by a colon (|:|) if it is at the start of the preview
262% snippet, and by a period (|.|) if it is at the end. The order of
263% different diagnostics like this being issued depends on the order
264% of the specification of the options when calling the package.
265%
266% Systems like \previewlatex\ use this for keeping counters accurate
267% when single previews are regenerated.
268% \item[|footnotes|] This makes footnotes render as previews, and only
269% as their footnote symbol. A convenient editing feature inside of
270% Emacs.
271% \end{description}
272% The following options are just for debugging purposes of the package
273% and similar to the corresponding \TeX\ commands they allude to:
274% \begin{description}
275% \item[|tracingall|] causes lots of diagnostic output to appear in
276% the log file during the preview collecting phases of \TeX's
277% operation. In contrast to the similarly named \TeX\ command, it
278% will not switch to |\errorstopmode|, nor will it change the
279% setting of |\tracingonline|.
280% \item[|showbox|] This option will show the contents of the boxes
281% shipped out to the DVI files. It also sets |\showboxbreadth| and
282% |\showboxdepth| to their maximum values at the end of loading this
283% package, but you may reset them if you don't like that.
284% \end{description}
285% \section{Provided Commands}
286% \DescribeEnv{preview} The |preview| environment causes its contents
287% to be set as a single preview image. Insertions like figures and
288% footnotes (except those included in minipages) will typically lead
289% to error messages or be lost. In case the |preview| package has not
290% been activated, the contents of this environment will be typeset
291% normally.
292%
293% \DescribeEnv{nopreview} The |nopreview| environment will cause its
294% contents not to undergo any special treatment by the |preview|
295% package. When |preview| is active, the contents will be discarded
296% like all main text that does not trigger the |preview| hooks. When
297% |preview| is not active, the contents will be typeset just like the
298% main text.
299%
300% Note that both of these environments typeset things as usual when
301% preview is not active. If you need something typeset conditionally,
302% use the \cmd{\ifPreview} conditional for it.
303%
304% \DescribeMacro{\PreviewMacro} If you want to make a macro like
305% \cmd{\includegraphics} (actually, this is what is done by the
306% |graphics| option to |preview|) produce a preview image, you put a
307% declaration like
308% \begin{quote}
309% |\PreviewMacro[*[[!]{\includegraphics}|
310% \end{quote}
311% or, more readable,
312% \begin{quote}
313% |\PreviewMacro[{*[][]{}}]{\includegraphics}|
314% \end{quote}
315% into your preamble. The optional argument to \cmd{\PreviewMacro}
316% specifies the arguments \cmd{\includegraphics} accepts, since this
317% is necessary information for properly ending the preview box. Note
318% that if you are using the more readable form, you have to enclose
319% the argument in a |[{| and |}]| pair. The inner braces are
320% necessary to stop any included |[]| pairs from prematurely ending
321% the optional argument, and to make a single |{}|
322% denoting an optional argument not get stripped away by \TeX's
323% argument parsing.
324%
325% The letters simply mean
326% \begin{description}
327% \item[|*|] indicates an optional |*| modifier, as in
328% |\includegraphics*|.
329% \item[|[|]^^A]
330% indicates an optional argument in brackets. This syntax
331% is somewhat baroque, but brief.
332% \item[{|[]|}] also indicates an optional argument in brackets. Be
333% sure to have encluded the entire optional argument specification
334% in an additional pair of braces as described above.
335% \item[|!|] indicates a mandatory argument.
336% \item[|\char`{\char`}|] indicates the same. Again, be sure to have
337% that additional level of braces around the whole argument
338% specification.
339% \item[|?|\meta{delimiter}\marg{true case}\marg{false case}] is a
340% conditional. The next character is checked against being equal to
341% \meta{delimiter}. If it is, the specification \meta{true case} is
342% used for the further parsing, otherwise \meta{false case} will be
343% employed. In neither case is something consumed from the input,
344% so \marg{true case} will still have to deal with the upcoming
345% delimiter.
346% \item[|@|\marg{literal sequence}] will insert the given sequence
347% literally into the executed call of the command.
348% \item[|-|] will just drop the next token. It will probably be most
349% often used in the true branch of a |?| specification.
350% \item[|\#|\marg{argument}\marg{replacement}] is a transformation
351% rule that calls a macro with the given argument and replacement
352% text on the rest of the argument list. The replacement is used in
353% the executed call of the command. This can be used for parsing
354% arbitrary constructs. For example, the |[]| option could manually
355% be implemented with the option string |?[{#{[#1]}{[{#1}]}}{}|.
356% PStricks users might enjoy this sort of flexibility.
357% \item[|:|\marg{argument}\marg{replacement}] is again a
358% transformation rule. As opposed to |#|, however, the result of
359% the transformation is parsed again. You'll rarely need this.
360% \end{description}
361%
362% There is a second optional argument in brackets that can be used to
363% declare any default action to be taken instead. This is mostly for
364% the sake of macros that influence numbering: you would want to keep
365% their effects in that respect. The default action should use |#1|
366% for referring to the original (not the patched) command with the
367% parsed options appended. Not specifying a second optional argument
368% here is equivalent to specifying~|[#1]|.
369%
370% \DescribeMacro{\PreviewMacro*} A similar invocation
371% \cmd{\PreviewMacro*} simply throws the macro and all of its
372% arguments declared in the manner above away. This is mostly useful
373% for having things like \cmd{\footnote} not do their magic on their
374% arguments. More often than not, you don't want to declare any
375% arguments to scan to \cmd{\PreviewMacro*} since you would want the
376% remaining arguments to be treated as usual text and typeset in that
377% manner instead of being thrown away. An exception might be, say,
378% sort keys for \cmd{\cite}.
379%
380% A second optional argument in brackets can be used to declare any
381% default action to be taken instead. This is for the sake of macros
382% that influence numbering: you would want to keep their effects in
383% that respect. The default action might use |#1| for referring to
384% the original (not the patched) command with the parsed options
385% appended. Not specifying a second optional argument here is
386% equivalent to specifying~|[]| since the command usually gets thrown
387% away.
388%
389% As an example for using this argument, you might want to specify
390% \begin{quote}
391% |\PreviewMacro*\footnote[{[]}][#1{}]|
392% \end{quote}
393% This will replace a footnote by an empty footnote, but taking any
394% optional parameter into account, since an optional paramter changes
395% the numbering scheme. That way the real argument for the footnote
396% remains for processing by \previewlatex.
397%
398% \DescribeMacro{\PreviewEnvironment} The macro
399% \cmd{\PreviewEnvironment} works just as \cmd{\PreviewMacro} does,
400% only for environments. \DescribeMacro{\PreviewEnvironment*} And the
401% same goes for \cmd{\PreviewEnvironment*} as compared to
402% \cmd{\PreviewMacro*}.
403%
404% \DescribeMacro{\PreviewSnarfEnvironment} This macro does not typeset
405% the original environment inside of a preview box, but instead
406% typesets just the contents of the original environment inside of the
407% preview box, leaving nothing for the original environment. This has
408% to be used for figures, for example, since they would
409% \begin{enumerate}
410% \item produce insertion material that cannot be extracted to the
411% preview properly,
412% \item complain with an error message about not being in outer par
413% mode.
414% \end{enumerate}
415%
416% \DescribeMacro{\PreviewOpen}
417% \DescribeMacro{\PreviewClose}
418% Those Macros form a matched preview pair. This is for macros that
419% behave similar as \cmd{\begin} and \cmd{\end} of an environment. It
420% is essential for the operation of \cmd{\PreviewOpen} that the macro
421% treated with it will open an additional group even when the preview
422% falls inside of another preview or inside of a |nopreview|
423% environment. Similarly, the macro treated with \cmd{PreviewClose}
424% will close an environment even when inactive.
425%
426% \DescribeMacro{\ifPreview} In case you need to know whether
427% |preview| is active, you can use the conditional \cmd{\ifPreview}
428% together with |\else| and |\fi|.
429%
430% \StopEventually{}
431% \section{The Implementation}
432% Here we go: the start is somewhat obtuse since we figure out version
433% number and date from RCS strings. This should really be done at
434% docstrip time instead. Takers?
435% \begin{macro}{\pr@version}
436% \begin{macrocode}
437%<*style>
438%<*!active>
439\NeedsTeXFormat{LaTeX2e} \def\reserved@a #1#2$#3:
440#4${\xdef#1{\reserved@c #2#4 $}} \def\reserved@c #1 #2${#1}
441\begingroup \catcode`\_=12
442\reserved@a\pr@version $Name: release_11_88 $ \ifx\pr@version\@empty
443\reserved@a\pr@version CVS-$Revision: 1.126 $ \endgroup \else
444 \def\next release_{} \lccode`\_=`.
445 \edef\next{\lowercase{\endgroup
446 \def\noexpand\pr@version{\expandafter\next\pr@version}}} \next \fi
447\reserved@a\next $Date: 2010/02/14 16:19:00 $
448\edef\next{\noexpand\ProvidesPackage{preview}%
449 [\next\space \pr@version\space (AUCTeX/preview-latex)]}
450\next
451% \end{macrocode}
452% \end{macro}
453% Since many parts here will not be needed as long as the package is
454% inactive, we will include them enclosed with |<*active>| and
455% |</active>| guards. That way, we can append all of this stuff at a
456% place where it does not get loaded if not necessary.
457%
458%\begin{macro}{\ifPreview}
459% Setting the \cmd{\ifPreview} command should not be done by the
460% user, so we don't use \cmd{\newif} here. As a consequence, there
461% are no \cmd{\Previewtrue} and \cmd{\Previewfalse} commands.
462% \begin{macrocode}
463\let\ifPreview\iffalse
464%</!active>
465% \end{macrocode}
466%\end{macro}
467%\begin{macro}{\ifpr@outer}
468% We don't allow previews inside of previews. The macro
469% \cmd{\ifpr@outer} can be used for checking whether we are outside
470% of any preview code.
471% \begin{macrocode}
472%<*active>
473\newif\ifpr@outer
474\pr@outertrue
475%</active>
476% \end{macrocode}
477%\end{macro}
478%
479%\begin{macro}{\preview@delay}
480% The usual meaning of \cmd{\preview@delay} is to just echo its
481% argument in normal |preview| operation. If |preview| is inactive,
482% it swallows its argument. If the |delayed| option is active, the
483% contents will be passed to the \cmd{\AtBeginDocument} hook.
484%\begin{macro}{\pr@advise}
485% The core macro for modifying commands is \cmd{\pr@advise}. You
486% pass it the original command name as first argument and what should
487% be executed before the saved original command as second argument.
488%\begin{macro}{\pr@advise@ship}
489% The most often used macro for modifying commands is
490% \cmd{\pr@advise@ship}. It receives three arguments. The first is
491% the macro to modify, the second specifies some actions to be done
492% inside of a box to be created before the original macro gets
493% executed, the third one specifies actions after the original macro
494% got executed.
495%\begin{macro}{\pr@loadcfg}
496% The macro \cmd{\pr@loadcfg} is used for loading in configuration
497% files, unless disabled by the |noconfig| option.
498% \begin{macrocode}
499%<*!active>
500\let\preview@delay=\@gobble
501\let\pr@advise=\@gobbletwo
502\long\def\pr@advise@ship#1#2#3{}
503\def\pr@loadcfg#1{\InputIfFileExists{#1.cfg}{}{}}
504\DeclareOption{noconfig}{\let\pr@loadcfg=\@gobble}
505% \end{macrocode}
506%\begin{macro}{\pr@addto@front}
507% This adds code globally to the front of a macro.
508% \begin{macrocode}
509\long\def\pr@addto@front#1#2{%
510 \toks@{#2}\toks@\expandafter{\the\expandafter\toks@#1}%
511 \xdef#1{\the\toks@}}
512% \end{macrocode}
513% \end{macro}
514% These commands get more interesting when |preview| is active:
515% \begin{macrocode}
516\DeclareOption{active}{%
517 \let\ifPreview\iftrue
518 \def\pr@advise#1{%
519 \expandafter\pr@adviseii\csname pr@\string#1\endcsname#1}%
520 \long\def\pr@advise@ship#1#2#3{\pr@advise#1{\pr@protect@ship{#2}{#3}}}%
521 \let\preview@delay\@firstofone}
522% \end{macrocode}
523% \end{macro}
524% \end{macro}
525% \end{macro}
526% \end{macro}
527%
528% \begin{macro}{\pr@adviseii}
529% Now \cmd{\pr@advise} needs its helper macro. In order to avoid
530% recursive definitions, we advise only macros that are not yet
531% advised. Or, more exactly, we throw away the old advice and only
532% take the new one. We use e\TeX's \cmd{\protected} where available
533% for some extra robustness.
534% \begin{macrocode}
535\long\def\pr@adviseii#1#2#3{\preview@delay{%
536 \ifx#1\relax \let#1#2\fi
537 \toks@{#3#1}%
538 \ifx\@undefined\protected \else \protected\fi
539 \long\edef#2{\the\toks@}}}
540% \end{macrocode}
541%\end{macro}
542%
543% The |delayed| option is easy to implement: this is \emph{not} done
544% with \cmd{\let} since at the course of document processing, \LaTeX\
545% redefines \cmd{\AtBeginDocument} and we want to follow that
546% redefinition.
547% \begin{macrocode}
548\DeclareOption{delayed}{%
549 \ifPreview \def\preview@delay{\AtBeginDocument}\fi
550}
551% \end{macrocode}
552%
553%\begin{macro}{\ifpr@fixbb}
554% Another conditional. \cmd{\ifpr@fixbb} tells us whether we want to
555% surround the typeset materials with invisible rules so that Dvips
556% gets the bounding boxes right for, say, pure PostScript inclusions.
557%
558% If you are installing this on an operating system different from
559% the one |preview| has been developed on, you might want to redefine
560% |\pr@markerbox| in your |prdefault.cfg| file to use a file known to
561% be empty, like |/dev/null| is under Unix. Make this redefinition
562% depend on \cmd{\ifpr@fixbb} since only then |\pr@markerbox| will be
563% defined.
564% \begin{macrocode}
565\newif\ifpr@fixbb
566\pr@fixbbfalse
567\DeclareOption{psfixbb}{\ifPreview%
568 \pr@fixbbtrue
569 \newbox\pr@markerbox
570 \setbox\pr@markerbox\hbox{\special{psfile=/dev/null}}\fi
571}
572% \end{macrocode}
573% \end{macro}
574% \begin{macro}{\pr@graphicstype}
575% The |dvips| option redefines the |bop-hook| to reset the page
576% size.
577% \begin{macrocode}
578\let\pr@graphicstype=\z@
579\DeclareOption{dvips}{%
580 \let\pr@graphicstype\@ne
581 \preview@delay{\AtBeginDvi{%
582 \special{!/preview@version(\pr@version)def}
583 \special{!userdict begin/preview-bop-level 0 def%
584 /bop-hook{/preview-bop-level dup load dup 0 le{/isls false def%
585 /vsize 792 def/hsize 612 def}if 1 add store}bind def%
586 /eop-hook{/preview-bop-level dup load dup 0 gt{1 sub}if
587 store}bind def end}}}}
588% \end{macrocode}
589% The |pdftex| option just sets \cmd{\pr@graphicstype}.
590% \begin{macrocode}
591\DeclareOption{pdftex}{%
592 \let\pr@graphicstype\tw@}
593% \end{macrocode}
594% And so does the |xetex| option.
595% \begin{macrocode}
596\DeclareOption{xetex}{%
597 \let\pr@graphicstype\thr@@}
598%</!active>
599% \end{macrocode}
600% \end{macro}
601% \subsection{The internals}
602%
603% Those are only needed if |preview| is active.
604% \begin{macrocode}
605%<*active>
606% \end{macrocode}
607% \begin{macro}{\pr@snippet}
608% \cmd{\pr@snippet} is the current snippet number. We need a
609% separate counter to \cmd{\c@page} since several other commands
610% might fiddle with the page number.
611% \begin{macrocode}
612\newcount\pr@snippet
613\global\pr@snippet=1
614% \end{macrocode}
615% \end{macro}
616% \begin{macro}{\pr@protect}
617% This macro gets one argument which is unpacked and executed in
618% typesetting situations where we are not yet inside of a preview.
619% \begin{macrocode}
620\def\pr@protect{\ifx\protect\@typeset@protect
621 \ifpr@outer \expandafter\expandafter\expandafter
622 \@secondoftwo\fi\fi\@gobble}
623% \end{macrocode}
624% \end{macro}
625% \begin{macro}{\pr@protect@ship}
626% Now for the above mentioned \cmd{\pr@protect@ship}. This gets
627% three arguments. The first is what to do at the beginning of the
628% preview, the second what to do at the end, the third is the macro
629% where we stored the original definition.
630%
631% In case we are not in a typesetting situation,
632% \cmd{\pr@protect@ship} leaves the stored macro to fend for its
633% own. No better or worse protection than the original. And we
634% only do anything different when \cmd{\ifpr@outer} turns out to be
635% true.
636% \begin{macrocode}
637\def\pr@protect@ship{\pr@protect{\@firstoftwo\pr@startbox}%
638 \@gobbletwo}
639% \end{macrocode}
640% \end{macro}
641% \begin{macro}{\pr@insert}
642% \begin{macro}{\pr@mark}
643% \begin{macro}{\pr@marks}
644% We don't want insertions to end up on our lists. So we disable
645% them right now by replacing them with the following:
646% \begin{macrocode}
647\def\pr@insert{\begingroup\afterassignment\pr@insertii\count@}
648\def\pr@insertii{\endgroup\setbox\pr@box\vbox}
649% \end{macrocode}
650% Similar things hold for marks.
651% \begin{macrocode}
652\def\pr@mark{{\afterassignment}\toks@}
653\def\pr@marks{{\aftergroup\pr@mark\afterassignment}\count@}
654% \end{macrocode}
655% \end{macro}
656% \end{macro}
657% \end{macro}
658% \begin{macro}{\pr@box}
659% \begin{macro}{\pr@startbox}
660% Previews will be stored in \cmd{\box}\cmd{\pr@box}.
661% \cmd{\pr@startbox} gets two arguments: code to execute immediately
662% before the following stuff, code to execute afterwards. You have
663% to cater for \cmd{\pr@endbox} being called at the right time
664% yourself. We will use a \cmd{\vsplit} on the box later in order
665% to remove any leading glues, penalties and similar stuff. For
666% this reason we start off the box with an optimal break point.
667% \begin{macrocode}
668\newbox\pr@box
669\long\def\pr@startbox#1#2{%
670 \ifpr@outer
671 \toks@{#2}%
672 \edef\pr@cleanup{\the\toks@}%
673 \setbox\pr@box\vbox\bgroup
674 \break
675 \pr@outerfalse\@arrayparboxrestore
676 \let\insert\pr@insert
677 \let\mark\pr@mark
678 \let\marks\pr@marks
679 \expandafter\expandafter\expandafter
680 \pr@ship@start
681 \expandafter\@firstofone
682 \else
683 \expandafter \@gobble
684 \fi{#1}}
685% \end{macrocode}
686% \end{macro}
687% \end{macro}
688% \begin{macro}{\pr@endbox}
689% Cleaning up also is straightforward. If we have to watch the
690% bounding \TeX\ box, we want to remove spurious skips. We also
691% want to unwrap a possible single line paragraph, so that the box
692% is not full line length. We use \cmd{\vsplit} to clean up leading
693% glue and stuff, and we make some attempt of removing trailing
694% ones. After that, we wrap up the box including possible material
695% from \cmd{\AtBeginDvi}. If the |psfixbb| option is active, we
696% adorn the upper left and lower right corners with copies of
697% \cmd{\pr@markerbox}. The first few lines cater for \LaTeX\ hiding
698% things like like the code for \cmd{\paragraph} in \cmd{\everypar}.
699% \begin{macrocode}
700\def\pr@endbox{%
701 \let\reserved@a\relax
702 \ifvmode \edef\reserved@a{\the\everypar}%
703 \ifx\reserved@a\@empty\else
704 \dimen@\prevdepth
705 \noindent\par
706 \setbox\z@\lastbox\unskip\unpenalty
707 \prevdepth\dimen@
708 \setbox\z@\hbox\bgroup\penalty-\maxdimen\unhbox\z@
709 \ifnum\lastpenalty=-\maxdimen\egroup
710 \else\egroup\box\z@ \fi\fi\fi
711 \ifhmode \par\unskip\setbox\z@\lastbox
712 \nointerlineskip\hbox{\unhbox\z@\/}%
713 \else \unskip\unpenalty\unskip \fi
714 \egroup
715 \setbox\pr@box\vbox{%
716 \baselineskip\z@skip \lineskip\z@skip \lineskiplimit\z@
717 \@begindvi
718 \nointerlineskip
719 \splittopskip\z@skip\setbox\z@\vsplit\pr@box to\z@
720 \unvbox\z@
721 \nointerlineskip
722 %\color@setgroup
723 \box\pr@box
724 %\color@endgroup
725 }%
726% \end{macrocode}
727% \begin{macro}{\pr@ship@end}
728% \label{sec:prshipend}At this point, \cmd{\pr@ship@end} gets
729% called. You must not under any circumstances change |\box\pr@box|
730% in any way that would add typeset material at the front of it,
731% except for PostScript header specials, since the front of
732% |\box\pr@box| may contain stuff from \cmd{\AtBeginDvi}.
733% \cmd{\pr@ship@end} contains two types of code additions: stuff
734% that adds to |\box\pr@box|, like the |labels| option does, and
735% stuff that measures out things or otherwise takes a look at the
736% finished |\box\pr@box|, like the |auctex| or |showbox| option do.
737% The former should use \cmd{pr@addto@front} for adding to this
738% hook, the latter use \cmd{g@addto@macro} for adding at the end of
739% this hook.
740%
741% Note that we shift the output box up by its height via
742% \cmd{\voffset}. This has three reasons: first we make sure that
743% no package-inflicted non-zero value of \cmd{\voffset} or
744% \cmd{\hoffset} will have any influence on the positioning of our
745% box. Second we shift the box such that its basepoint will exactly
746% be at the (1in,1in)~mark defined by \TeX. That way we can
747% properly take ascenders into account. And the third reason is
748% that \TeX\ treats a \cmd{\hbox} and a \cmd{\vbox} differently with
749% regard to the treating of its depth. Shifting \cmd{\voffset} and
750% \cmd{\hoffset} can be inhibited by setting |\pr@offset@override|.
751% \begin{macrocode}
752 \pr@ship@end
753 {\let\protect\noexpand
754 \ifx\pr@offset@override\@undefined
755 \voffset=-\ht\pr@box
756 \hoffset=\z@
757 \fi
758 \c@page=\pr@snippet
759 \pr@shipout
760 \ifpr@fixbb\hbox{%
761 \dimen@\wd\pr@box
762 \@tempdima\ht\pr@box
763 \@tempdimb\dp\pr@box
764 \box\pr@box
765 \llap{\raise\@tempdima\copy\pr@markerbox\kern\dimen@}%
766 \lower\@tempdimb\copy\pr@markerbox}%
767 \else \box\pr@box \fi}%
768 \global\advance\pr@snippet\@ne
769 \pr@cleanup
770}
771% \end{macrocode}
772% \end{macro}
773% \end{macro}
774% Oh, and we kill off the usual meaning of \cmd{\shipout} in case
775% somebody makes a special output routine. The following test is
776% pretty much the same as in |everyshi.sty|. One of its implications
777% is that if someone does a \cmd{\shipout} of a \emph{void} box,
778% things will go horribly wrong.
779% \begin{macro}{\shipout}
780% \begin{macrocode}
781\let\pr@shipout=\shipout
782\def\shipout{\deadcycles\z@\bgroup\setbox\z@\box\voidb@x
783 \afterassignment\pr@shipoutegroup\setbox\z@}
784\def\pr@shipoutegroup{\ifvoid\z@ \expandafter\aftergroup\fi \egroup}
785% \end{macrocode}
786% \end{macro}
787% \subsection{Parsing commands}
788% \begin{macro}{\pr@parseit}
789% \begin{macro}{\pr@endparse}
790% \begin{macro}{\pr@callafter}
791% The following stuff is for parsing the arguments of commands we
792% want to somehow surround with stuff. Usage is
793% \begin{quote}
794% \cmd{\pr@callafter}\meta{aftertoken}\meta{parsestring}\cmd{\pr@endparse}\\
795% \qquad\meta{macro}\meta{parameters}
796% \end{quote}
797% \meta{aftertoken} is stored away and gets executed once parsing
798% completes, with its first argument being the parsed material.
799% \meta{parsestring} would be, for example for the
800% \cmd{\includegraphics} macro, |*[[!|, an optional |*| argument
801% followed by two optional arguments enclosed in |[]|, followed by
802% one mandatory argument.
803%
804% For the sake of a somewhat more intuitive syntax, we now support
805% also the syntax |{*[]{}}| in the optional argument. Since \TeX\
806% strips redundant braces, we have to write |[{{}}]| in this syntax
807% for a single mandatory argument. Hard to avoid. We use an
808% unusual character for ending the parsing. The implementation is
809% rather trivial.
810% \begin{macrocode}
811\def\pr@parseit#1{\csname pr@parse#1\endcsname}
812\let\pr@endparse=\@percentchar
813\def\next#1{%
814\def\pr@callafter{%
815 \afterassignment\pr@parseit
816 \let#1= }}
817\expandafter\next\csname pr@parse\pr@endparse\endcsname
818% \end{macrocode}
819% \end{macro}
820% \end{macro}
821% \end{macro}
822% \begin{macro}{\pr@parse*}
823% Straightforward, same mechanism \LaTeX\ itself employs. We take
824% some care not to pass potential |#| tokens unprotected through
825% macros.
826% \begin{macrocode}
827\long\expandafter\def\csname pr@parse*\endcsname#1\pr@endparse#2{%
828 \begingroup\toks@{#1\pr@endparse{#2}}%
829 \edef\next##1{\endgroup##1\the\toks@}%
830 \@ifstar{\next{\pr@parse@*}}{\next\pr@parseit}}
831% \end{macrocode}
832% \end{macro}
833% \begin{macro}{\pr@parse[}
834% \begin{macro}{\pr@brace}
835% Copies optional parameters in brackets if present. The additional
836% level of braces is necessary to ensure that braces the user might
837% have put to hide a~|]| bracket in an optional argument don't get
838% lost. There will be no harm if such braces were not there at the
839% start.
840% \begin{macrocode}
841\long\expandafter\def\csname pr@parse[\endcsname#1\pr@endparse#2{%
842 \begingroup\toks@{#1\pr@endparse{#2}}%
843 \edef\next##1{\endgroup##1\the\toks@}%
844 \@ifnextchar[{\next\pr@bracket}{\next\pr@parseit}}
845\long\def\pr@bracket#1\pr@endparse#2[#3]{%
846 \pr@parseit#1\pr@endparse{#2[{#3}]}}
847% \end{macrocode}
848% \end{macro}
849% \end{macro}
850% \begin{macro}{\pr@parse]}
851% This is basically a do-nothing, so that we may use the syntax
852% |{*[][]!}| in the optional argument instead of the more concise
853% but ugly |*[[!| which confuses the brace matchers of editors.
854% \begin{macrocode}
855\expandafter\let\csname pr@parse]\endcsname=\pr@parseit
856% \end{macrocode}
857% \end{macro}
858% \begin{macro}{\pr@parse}
859% \begin{macro}{\pr@parse!}
860% Mandatory arguments are perhaps easiest to parse.
861% \begin{macrocode}
862\long\def\pr@parse#1\pr@endparse#2#3{%
863 \pr@parseit#1\pr@endparse{#2{#3}}}
864\expandafter\let\csname pr@parse!\endcsname=\pr@parse
865% \end{macrocode}
866% \end{macro}
867% \end{macro}
868% \begin{macro}{\pr@parse?}
869% \begin{macro}{\pr@parsecond}
870% This does an explicit call of |\@ifnextchar| and forks into the
871% given two alternatives as a result.
872% \begin{macrocode}
873\long\expandafter\def\csname pr@parse?\endcsname#1#2\pr@endparse#3{%
874 \begingroup\toks@{#2\pr@endparse{#3}}%
875 \@ifnextchar#1{\pr@parsecond\@firstoftwo}%
876 {\pr@parsecond\@secondoftwo}}
877\def\pr@parsecond#1{\expandafter\endgroup
878 \expandafter\expandafter\expandafter\pr@parseit
879 \expandafter#1\the\toks@}
880% \end{macrocode}
881% \end{macro}
882% \end{macro}
883% \begin{macro}{\pr@parse@}
884% This makes it possible to insert literal material into the
885% argument list.
886% \begin{macrocode}
887 \long\def\pr@parse@#1#2\pr@endparse#3{%
888 \pr@parseit #2\pr@endparse{#3#1}}
889% \end{macrocode}
890% \end{macro}
891% \begin{macro}{\pr@parse-}
892% This will just drop the next token.
893% \begin{macrocode}
894\long\expandafter\def\csname pr@parse-\endcsname
895 #1\pr@endparse#2{\begingroup
896 \toks@{\endgroup\pr@parseit #1\pr@endparse{#2}}%
897 {\aftergroup\the\aftergroup\toks@ \afterassignment}%
898 \let\next= }
899% \end{macrocode}
900% \end{macro}
901% \begin{macro}{\pr@parse:}
902% The following is a transform rule. A macro is being defined with
903% the given argument list and replacement, and the transformed
904% version replaces the original. The result of the transform is
905% still subject to being parsed.
906% \begin{macrocode}
907\long\expandafter\def\csname pr@parse:\endcsname
908 #1#2#3\pr@endparse#4{\begingroup
909 \toks@{\endgroup \pr@parseit#3\pr@endparse{#4}}%
910 \long\def\next#1{#2}%
911 \the\expandafter\toks@\next}
912% \end{macrocode}
913% \end{macro}
914% \edef\next{\noexpand\begin{macro}{\noexpand
915% \pr@parse\string#}}
916% \next
917% Another transform rule, but this passes the transformed material
918% into the token list.
919% \begin{macrocode}
920\long\expandafter\def\csname pr@parse#\endcsname
921 #1#2#3\pr@endparse#4{\begingroup
922 \toks@{#4}%
923 \long\edef\next##1{\toks@{\the\toks@##1}}%
924 \toks@{\endgroup \pr@parseit#3\pr@endparse}%
925 \long\def\reserved@a#1{{#2}}%
926 \the\expandafter\next\reserved@a}
927%</active>
928% \end{macrocode}
929% \end{macro}
930%
931% \subsection{Selection options}
932% The |displaymath| option. The |equation| environments in AMS\LaTeX\
933% already do too much before our hook gets to interfere, so we hook
934% earlier. Some juggling is involved to ensure we get the original
935% |\everydisplay| tokens only once and where appropriate.
936%
937% The incredible hack with |\dt@ptrue| is necessary for working around
938% bug `amslatex/3425'.
939% \begin{macrocode}
940%<*!active>
941\begingroup
942\catcode`\*=11
943\@firstofone{\endgroup
944\DeclareOption{displaymath}{%
945 \preview@delay{\toks@{%
946 \pr@startbox{\noindent$$%
947 \aftergroup\pr@endbox\@gobbletwo}{$$}\@firstofone}%
948 \everydisplay\expandafter{\the\expandafter\toks@
949 \expandafter{\the\everydisplay}}}%
950 \pr@advise@ship\equation{\begingroup\aftergroup\pr@endbox
951 \def\dt@ptrue{\m@ne=\m@ne}\noindent}%
952 {\endgroup}%
953 \pr@advise@ship\equation*{\begingroup\aftergroup\pr@endbox
954 \def\dt@ptrue{\m@ne=\m@ne}\noindent}%
955 {\endgroup}%
956 \PreviewOpen[][\def\dt@ptrue{\m@ne=\m@ne}\noindent#1]\[%
957 \PreviewClose\]%
958 \PreviewEnvironment[][\noindent#1]{eqnarray}%
959 \PreviewEnvironment[][\noindent#1]{eqnarray*}%
960 \PreviewEnvironment{displaymath}%
961}}
962% \end{macrocode}
963%
964% The |textmath| option. Some folderol in order to define the active
965% |$|
966% math mode delimiter. \cmd\pr@textmathcheck is used for checking
967% whether we have a single |$| or double |$$|.
968% In the latter case, we enter display math (this sort of display math
969% is not allowed inside of \LaTeX\ because of inconsistent spacing,
970% but surprisingly many people use it nevertheless). Strictly
971% speaking, this is incorrect, since not every
972% |$$| actually means display math. For example, |\hbox{$$}| will
973% because of restricted horizontal mode rather yield an empty text
974% math formula. Since our implementation moved the sequence inside of
975% a |\vbox|, the interpretation will change. People should just not
976% enter rubbish like that.
977% \begin{macrocode}
978\begingroup
979\def\next#1#2{%
980 \endgroup
981 \DeclareOption{textmath}{%
982 \PreviewEnvironment{math}%
983 \preview@delay{\ifx#1\@undefined \let#1=$%$
984 \fi\catcode`\$=\active
985 \ifx\xyreuncatcodes\@undefined\else
986 \edef\next{\catcode`@=\the\catcode`@\relax}%
987 \makeatother\expandafter\xyreuncatcodes\next\fi}%
988 \pr@advise@ship\(\pr@endaftergroup{}% \)
989 \pr@advise@ship#1{\@firstoftwo{\let#1=#2%
990 \futurelet\reserved@a\pr@textmathcheck}}{}}%
991 \def\pr@textmathcheck{\expandafter\pr@endaftergroup
992 \ifx\reserved@a#1{#2#2}\expandafter\@gobbletwo\fi#2}}
993\lccode`\~=`\$
994\lowercase{\expandafter\next\expandafter~}%
995 \csname pr@\string$%$
996 \endcsname
997%</!active>
998% \end{macrocode}
999% \begin{macro}{\pr@endaftergroup}
1000% This justs ends the box after the group opened by |#1| is closed
1001% again.
1002% \begin{macrocode}
1003%<*active>
1004\def\pr@endaftergroup#1{#1\aftergroup\pr@endbox}
1005%</active>
1006% \end{macrocode}
1007% \end{macro}
1008%
1009% The |graphics| option.
1010% \begin{macrocode}
1011%<*!active>
1012\DeclareOption{graphics}{%
1013 \PreviewMacro[*[[!]{\includegraphics}%]]
1014}
1015% \end{macrocode}
1016% The |floats| option. The complications here are merely to spare us
1017% bug reports about broken document classes that use |\let| on
1018% |\endfigure| and similar. Notable culprits that have not been
1019% changed in years in spite of reports are |elsart.cls| and
1020% |IEEEtran.cls|. Complain when you are concerned.
1021% \begin{macrocode}
1022\def\pr@floatfix#1#2{\ifx#1#2%
1023 \ifx#1\@undefined\else
1024 \PackageWarningNoLine{preview}{%
1025Your document class has a bad definition^^J
1026of \string#1, most likely^^J
1027\string\let\string#1=\string#2^^J
1028which has now been changed to^^J
1029\string\def\string#1{\string#2}^^J
1030because otherwise subsequent changes to \string#2^^J
1031(like done by several packages changing float behaviour)^^J
1032can't take effect on \string#1.^^J
1033Please complain to your document class author}%
1034 \def#1{#2}\fi\fi}
1035\begingroup
1036\def\next#1#2{\endgroup
1037 \DeclareOption{floats}{%
1038 \pr@floatfix\endfigure\end@float
1039 \pr@floatfix\endtable\end@float
1040 \pr@floatfix#1\end@dblfloat
1041 \pr@floatfix#2\end@dblfloat
1042 \PreviewSnarfEnvironment[![]{@float}%]
1043 \PreviewSnarfEnvironment[![]{@dblfloat}%]
1044 }}
1045\expandafter\next\csname endfigure*\expandafter\endcsname
1046 \csname endtable*\endcsname
1047% \end{macrocode}
1048% The |sections| option. Two optional parameters might occur in
1049% |memoir.cls|.
1050% \begin{macrocode}
1051\DeclareOption{sections}{%
1052 \PreviewMacro[!!!!!!*[[!]{\@startsection}%]]
1053 \PreviewMacro[*[[!]{\chapter}%]]
1054}
1055% \end{macrocode}
1056% We now interpret any further options as driver files we load. Note
1057% that these driver files are loaded even when |preview| is not
1058% active. The reason is that they might define commands (like
1059% \cmd{\PreviewCommand}) that should be available even in case of an
1060% inactive package. Large parts of the |preview| package will not
1061% have been loaded in this case: you have to cater for that.
1062% \begin{macrocode}
1063\DeclareOption*
1064 {\InputIfFileExists{pr\CurrentOption.def}{}{\OptionNotUsed}}
1065% \end{macrocode}
1066%
1067% \subsection{Preview attaching commands}
1068% \begin{macro}{\PreviewMacro}
1069% As explained above. Detect possible |*| and call appropriate
1070% macro.
1071% \begin{macrocode}
1072\def\PreviewMacro{\@ifstar\pr@starmacro\pr@macro}
1073% \end{macrocode}
1074% The version without |*| is now rather straightforward.
1075% \begin{macro}{\pr@macro}
1076% \begin{macro}{\pr@domacro}
1077% \begin{macro}{\pr@macroii}
1078% \begin{macro}{\pr@endmacro}
1079% \begin{macrocode}
1080\long\def\pr@domacro#1#2{%
1081 \long\def\next##1{#2}%
1082 \pr@callafter\next#1]\pr@endparse}
1083\newcommand\pr@macro[1][]{%
1084 \toks@{\pr@domacro{#1}}%
1085 \long\edef\next[##1]##2{%
1086 \noexpand\pr@advise@ship{##2}{\the\toks@{##1\noexpand\pr@endbox}}{}}%
1087 \@ifnextchar[\next\pr@macroii}
1088\def\pr@macroii{\next[##1]}
1089\long\def\pr@endmacro#1{#1\pr@endbox}
1090% \end{macrocode}
1091% \end{macro}
1092% \end{macro}
1093% \end{macro}
1094% \end{macro}
1095% \end{macro}
1096% \begin{macro}{PreviewMacro*}
1097% \begin{macro}{\pr@protect@domacro}
1098% \begin{macro}{\pr@starmacro}
1099% The version with |*| has to parse the arguments, then throw them
1100% away. Some internal macros first, then the interface call.
1101% \begin{macrocode}
1102\long\def\pr@protect@domacro#1#2{\pr@protect{%
1103 \long\def\next##1{#2}%
1104 \pr@callafter\next#1]\pr@endparse}}
1105\newcommand\pr@starmacro[1][]{\toks@{\pr@protect@domacro{#1}}%
1106 \long\edef\next[##1]##2{%
1107 \noexpand\pr@advise##2{\the\toks@{##1}}}%
1108 \@ifnextchar[\next{\next[]}}
1109% \end{macrocode}
1110% \end{macro}
1111% \end{macro}
1112% \end{macro}
1113% \begin{macro}{\PreviewOpen}
1114% As explained above. Detect possible |*| and call appropriate macro.
1115% \begin{macrocode}
1116\def\PreviewOpen{\@ifstar\pr@starmacro\pr@open}
1117% \end{macrocode}
1118% The version without |*| is now rather straightforward.
1119% \begin{macro}{\pr@open}
1120% \begin{macrocode}
1121\newcommand\pr@open[1][]{%
1122 \toks@{\pr@domacro{#1}}%
1123 \long\edef\next[##1]##2{%
1124 \noexpand\pr@advise##2{\begingroup
1125 \noexpand\pr@protect@ship
1126 {\the\toks@{\begingroup\aftergroup\noexpand\pr@endbox##1}}%
1127 {\endgroup}}}%
1128 \@ifnextchar[\next\pr@macroii}
1129% \end{macrocode}
1130% \end{macro}
1131% \end{macro}
1132% \begin{macro}{\PreviewClose}
1133% As explained above. Detect possible |*| and call appropriate
1134% macro.
1135% \begin{macrocode}
1136\def\PreviewClose{\@ifstar\pr@starmacro\pr@close}
1137% \end{macrocode}
1138% The version without |*| is now rather straightforward.
1139% \begin{macro}{\pr@close}
1140% \begin{macrocode}
1141\newcommand\pr@close[1][]{%
1142 \toks@{\pr@domacro{#1}}%
1143 \long\edef\next[##1]##2{%
1144 \noexpand\pr@advise{##2}{\the\toks@{##1\endgroup}}}%
1145 \@ifnextchar[\next\pr@macroii}
1146% \end{macrocode}
1147% \end{macro}
1148% \end{macro}
1149% \begin{macro}{\PreviewEnvironment}
1150% Actually, this ignores any syntax argument. But don't tell
1151% anybody. Except for the |*|~variant, it respects (actually
1152% ignores) any argument! Of course, we'll need to deactivate
1153% |\end{|\meta{environment}|}| as well.
1154% \begin{macrocode}
1155\def\PreviewEnvironment{\@ifstar\pr@starenv\pr@env}
1156\newcommand\pr@starenv[1][]{\toks@{\pr@starmacro[{#1}]}%
1157 \long\edef\next##1##2{%
1158 \the\toks@[{##2}]##1}%
1159 \begingroup\pr@starenvii}
1160\newcommand\pr@starenvii[2][]{\endgroup
1161 \expandafter\next\csname#2\endcsname{#1}%
1162 \expandafter\pr@starmacro\csname end#2\endcsname}
1163\newcommand\pr@env[1][]{%
1164 \toks@{\pr@domacro{#1}}%
1165 \long\edef\next[##1]##2{%
1166 \noexpand\expandafter\noexpand\pr@advise@ship
1167 \noexpand\csname##2\noexpand\endcsname{\the\toks@
1168 {\begingroup\aftergroup\noexpand\pr@endbox##1}}{\endgroup}}%
1169 \@ifnextchar[\next\pr@macroii %]
1170 }
1171% \end{macrocode}
1172% \end{macro}
1173% \begin{macro}{\PreviewSnarfEnvironment}
1174% This is a nuisance since we have to advise \emph{both} the
1175% environment and its end.
1176% \begin{macrocode}
1177\newcommand{\PreviewSnarfEnvironment}[2][]{%
1178 \expandafter\pr@advise
1179 \csname #2\endcsname{\pr@snarfafter{#1}}%
1180 \expandafter\pr@advise
1181 \csname end#2\endcsname{\pr@endsnarf}}
1182%</!active>
1183% \end{macrocode}
1184% \end{macro}
1185% \begin{macro}{\pr@snarfafter}
1186% \begin{macro}{\pr@startsnarf}
1187% \begin{macro}{\pr@endsnarf}
1188% Ok, this looks complicated, but we have to start a group in order
1189% to be able to hook \cmd{\pr@endbox} into the game only when
1190% \cmd{\ifpr@outer} has triggered the start. And we need to get our
1191% start messages out before parsing the arguments.
1192% \begin{macrocode}
1193%<*active>
1194\let\pr@endsnarf\relax
1195\long\def\pr@snarfafter#1{\ifpr@outer
1196 \pr@ship@start
1197 \let\pr@ship@start\relax
1198 \let\pr@endsnarf\endgroup
1199 \else
1200 \let\pr@endsnarf\relax
1201 \fi
1202 \pr@protect{\pr@callafter\pr@startsnarf#1]\pr@endparse}}
1203\def\pr@startsnarf#1{#1\begingroup
1204 \pr@startbox{\begingroup\aftergroup\pr@endbox}{\endgroup}%
1205 \ignorespaces}
1206%</active>
1207% \end{macrocode}
1208% \end{macro}
1209% \end{macro}
1210% \end{macro}
1211% \begin{macro}{\pr@ship@start}
1212% \begin{macro}{\pr@ship@end}
1213% The hooks \cmd{\pr@ship@start} and \cmd{\pr@ship@end} can be added
1214% to by option files by the help of the \cmd{\g@addto@macro} command
1215% from \LaTeX, and by the \cmd{\pr@addto@front} command from
1216% |preview.sty| itself. They are called just before starting to
1217% process some preview, and just after it. Here is the policy for
1218% adding to them: \cmd{\pr@ship@start} is called inside of the vbox
1219% |\pr@box| before typeset material gets produced. It is, however,
1220% preceded by a break command that is intended for usage in
1221% \cmd{\vsplit}, so that any following glue might disappear. In
1222% case you want to add any material on the list, you have to precede
1223% it with \cmd{\unpenalty} and have to follow it with \cmd{\break}.
1224% You have make sure that under no circumstances any other legal
1225% breakpoints appear before that, and your material should
1226% contribute no nonzero dimensions to the page. For the policies of
1227% the \cmd{\pr@ship@end} hook, see the description on
1228% page~\pageref{sec:prshipend}.
1229% \begin{macrocode}
1230%<*!active>
1231\let\pr@ship@start\@empty
1232\let\pr@ship@end\@empty
1233% \end{macrocode}
1234% \end{macro}
1235% \end{macro}
1236% \begin{environment}{preview}
1237% \begin{environment}{nopreview}
1238% First we write the definitions of these environments when
1239% |preview| is inactive. We will redefine them if |preview| gets
1240% activated.
1241% \begin{macrocode}
1242\newenvironment{preview}{\ignorespaces}{\ifhmode\unskip\fi}
1243\newenvironment{nopreview}{\ignorespaces}{\ifhmode\unskip\fi}
1244% \end{macrocode}
1245% \end{environment}
1246% \end{environment}
1247%
1248% We now process the options and finish in case we are not active.
1249% \begin{macrocode}
1250\ProcessOptions\relax
1251\ifPreview\else\expandafter\endinput\fi
1252%</!active>
1253% \end{macrocode}
1254% Now for the redefinition of the |preview| and |endpreview|
1255% environments:
1256% \begin{macrocode}
1257%<*active>
1258\renewenvironment{preview}{\begingroup
1259 \pr@startbox{\begingroup\aftergroup\pr@endbox}%
1260 {\endgroup}%
1261 \ignorespaces}%
1262 {\ifhmode\unskip\fi\endgroup}
1263\renewenvironment{nopreview}{\pr@outerfalse\ignorespaces}%
1264 {\ifhmode\unskip\fi}
1265% \end{macrocode}
1266% We use the normal output routine, but hijack it a bit for our
1267% purposes to preserve \cmd{\AtBeginDvi} hooks and not get previews
1268% while in output: that could become rather ugly.
1269%
1270% The main work of disabling normal output relies on a \cmd{\shipout}
1271% redefinition.
1272% \begin{macro}{\pr@output}
1273% \begin{macrocode}
1274\newtoks\pr@output
1275\pr@output\output
1276\output{%
1277 \pr@outerfalse
1278 \let\@begindvi\@empty
1279 \the\pr@output}
1280\let\output\pr@output
1281% \end{macrocode}
1282% \end{macro}
1283% \begin{macro}{\pr@typeinfos}
1284% Then we have some document info that style files might want to
1285% output.
1286% \begin{macrocode}
1287\def\pr@typeinfos{\typeout{Preview: Fontsize \f@size pt}%
1288 \ifnum\mag=\@m\else\typeout{Preview: Magnification \number\mag}\fi
1289 \ifx\pdfoutput\@undefined
1290 \ifx\XeTeXversion\@undefined \else
1291 % FIXME: The message should not be emitted if XeTeX does not produce
1292 % PDF. There does not seem to be a primitive for that, though.
1293 \typeout{Preview: PDFoutput 1}%
1294 \fi
1295 \else
1296 \ifx\pdfoutput\relax \else
1297 \ifnum\pdfoutput>\z@
1298 \typeout{Preview: PDFoutput 1}%
1299 \fi
1300 \fi
1301 \fi
1302}
1303\AtBeginDocument{\pr@typeinfos}
1304% \end{macrocode}
1305% \end{macro}
1306% And at the end we load the default configuration file, so that it
1307% may override settings from this package:
1308% \begin{macrocode}
1309\pr@loadcfg{prdefault}
1310%</active>
1311%</style>
1312% \end{macrocode}
1313%
1314% \section{The option files}
1315% \subsection{The \texttt{auctex} option}
1316% The AUC\TeX\ option will cause error messages to spew. We want them
1317% on the terminal, but we don't want \LaTeX\ to stop its automated
1318% run. We delay \cmd{\nonstopmode} in case the user has any
1319% pseudo-interactive folderol like reading in of file names in his
1320% preamble. Because we are so good-hearted, we will not break this as
1321% long as the document has not started, but after that we need the
1322% error message mechanism operative.
1323%
1324% The |\nofiles| command here tries to avoid clobbering input files
1325% used for references and similar. It will come too late if you call
1326% the package with \cmd{\AtBeginDocument}, so you'll need to issue
1327% |\nofiles| yourself in that case. Previously, this was done
1328% unconditionally in the main style file, but since we don't know what
1329% the package may be used for, this was inappropriate.
1330%
1331% So here is the contents of the |prauctex.def| file:
1332% \begin{macrocode}
1333%<auctex>\ifPreview\else\expandafter\endinput\fi
1334%<auctex>\nofiles
1335%<auctex>\preview@delay{\nonstopmode}
1336% \end{macrocode}
1337% Ok, here comes creative error message formatting. It turns out a
1338% sizable portion of the runtime is spent in I/O. Making the error
1339% messages short is an advantage. It is not possible to convince
1340% \TeX\ to make shorter error messages than this: \TeX\ always wants
1341% to include context. This is about the shortest \ae sthetic one we
1342% can muster.
1343% \begin{macrocode}
1344%<auctex>\begingroup
1345%<auctex>\lccode`\~=`\-
1346%<auctex>\lccode`\{=`\<
1347%<auctex>\lccode`\}=`\>
1348%<auctex>\lowercase{\endgroup
1349%<auctex> \def\pr@msgi{{~}}}
1350%<auctex>\def\pr@msgii{Preview:
1351%<auctex> Snippet \number\pr@snippet\space}
1352%<auctex>\begingroup
1353%<auctex>\catcode`\-=13
1354%<auctex>\catcode`\<=13
1355%<auctex>\@firstofone{\endgroup
1356%<auctex>\def\pr@msg#1{{%
1357%<auctex> \let<\pr@msgi
1358%<auctex> \def-{\pr@msgii#1}%
1359%<auctex> \errhelp{Not a real error.}%
1360%<auctex> \errmessage<}}}
1361%<auctex>\g@addto@macro\pr@ship@start{\pr@msg{started}}
1362%<auctex>\g@addto@macro\pr@ship@end{\pr@msg{ended.%
1363%<auctex> (\number\ht\pr@box+\number\dp\pr@box x\number\wd\pr@box)}}
1364% \end{macrocode}
1365% This looks pretty baffling, but it produces something short and
1366% semi-graphical, namely |<-><->|. That is a macro |<| that expands
1367% into |<->|, where |<| and |>| are the braces around an
1368% \cmd{\errmessage} argument and |-| is a macro expanding to the full
1369% text of the error message. Cough cough. You did not really want to
1370% know, did you?
1371%
1372% Since over/underfull boxes are about the messiest things to parse,
1373% we disable them by setting the appropriate badness limits and making
1374% the variables point to junk. We also disable other stuff. While we
1375% set \cmd{\showboxbreadth} and \cmd{\showboxdepth} to indicate as
1376% little diagnostic output as possible, we keep them operative, so
1377% that the user retains the option of debugging using this stuff. The
1378% other variables concerning the generation of warnings and
1379% daignostics, however, are more often set by commonly employed
1380% packages and macros such as \cmd{\sloppy}. So we kill them off for
1381% good.
1382% \begin{macrocode}
1383%<auctex>\hbadness=\maxdimen
1384%<auctex>\newcount\hbadness
1385%<auctex>\vbadness=\maxdimen
1386%<auctex>\let\vbadness=\hbadness
1387%<auctex>\hfuzz=\maxdimen
1388%<auctex>\newdimen\hfuzz
1389%<auctex>\vfuzz=\maxdimen
1390%<auctex>\let\vfuzz=\hfuzz
1391%<auctex>\showboxdepth=-1
1392%<auctex>\showboxbreadth=-1
1393% \end{macrocode}
1394% Ok, now we load a possible configuration file.
1395% \begin{macrocode}
1396%<auctex>\pr@loadcfg{prauctex}
1397% \end{macrocode}
1398% And here we cater for several frequently used commands in
1399% |prauctex.cfg|:
1400% \begin{macrocode}
1401%<auccfg>\PreviewMacro*[[][#1{}]\footnote
1402%<auccfg>\PreviewMacro*[?[{@{[]}}{}][#1]\item
1403%<auccfg>\PreviewMacro*\emph
1404%<auccfg>\PreviewMacro*\textrm
1405%<auccfg>\PreviewMacro*\textit
1406%<auccfg>\PreviewMacro*\textsc
1407%<auccfg>\PreviewMacro*\textsf
1408%<auccfg>\PreviewMacro*\textsl
1409%<auccfg>\PreviewMacro*\texttt
1410%<auccfg>\PreviewMacro*\textcolor
1411%<auccfg>\PreviewMacro*\mbox
1412%<auccfg>\PreviewMacro*[][#1{}]\author
1413%<auccfg>\PreviewMacro*[][#1{}]\title
1414%<auccfg>\PreviewMacro*\and
1415%<auccfg>\PreviewMacro*\thanks
1416%<auccfg>\PreviewMacro*[][#1{}]\caption
1417%<auccfg>\preview@delay{\@ifundefined{pr@\string\@startsection}{%
1418%<auccfg> \PreviewMacro*[!!!!!!*][#1{}]\@startsection}{}}
1419%<auccfg>\preview@delay{\@ifundefined{pr@\string\chapter}{%
1420%<auccfg> \PreviewMacro*[*][#1{}]\chapter}{}}
1421%<auccfg>\PreviewMacro*\index
1422% \end{macrocode}
1423%
1424% \subsection{The \texttt{lyx} option}
1425% The following is the option providing LyX with info for its preview
1426% implementation.
1427% \begin{macrocode}
1428%<lyx>\ifPreview\else\expandafter\endinput\fi
1429%<lyx>\pr@loadcfg{prlyx}
1430%<lyx>\g@addto@macro\pr@ship@end{\typeout{Preview:
1431%<lyx> Snippet \number\pr@snippet\space
1432%<lyx> \number\ht\pr@box\space \number\dp\pr@box \space\number\wd\pr@box}}
1433% \end{macrocode}
1434%
1435% \subsection{The \texttt{counters} option}
1436% This outputs a checkpoint. We do this by saving all counter
1437% registers in backup macros starting with |\pr@c@| in their name. A
1438% checkpoint first writes out all changed counters (previously
1439% unchecked counters are not written out unless different from zero),
1440% then saves all involved counter values. \LaTeX\ tracks its counters
1441% in the global variable \cmd{\cl@ckpt}.
1442% \begin{macrocode}
1443%<counters>\ifPreview\else\expandafter\endinput\fi
1444%<counters>\def\pr@eltprint#1{\expandafter\@gobble\ifnum\value{#1}=0%
1445%<counters> \csname pr@c@#1\endcsname\else\relax
1446%<counters> \space{#1}{\arabic{#1}}\fi}
1447%<counters>\def\pr@eltdef#1{\expandafter\xdef
1448%<counters> \csname pr@c@#1\endcsname{\arabic{#1}}}
1449%<counters>\def\pr@ckpt#1{{\let\@elt\pr@eltprint\edef\next{\cl@@ckpt}%
1450%<counters> \ifx\next\@empty\else\typeout{Preview: Counters\next#1}%
1451%<counters> \let\@elt\pr@eltdef\cl@@ckpt\fi}}
1452%<counters>\pr@addto@front\pr@ship@start{\pr@ckpt:}
1453%<counters>\pr@addto@front\pr@ship@end{\pr@ckpt.}
1454% \end{macrocode}
1455%
1456% \subsection{Debugging options}
1457% Those are for debugging the operation of |preview|, and thus are
1458% mostly of interest for people that want to use |preview| for their
1459% own purposes. Since debugging output is potentially confusing to
1460% the error message parsing from AUC\TeX, you should not turn on
1461% |\tracingonline| or switch from |\nonstopmode| unless you are
1462% certain your package will never be used with \previewlatex.
1463%
1464% \paragraph{The \texttt{showbox} option} will generate diagnostic
1465% output for every produced box. It does not delay the resetting of
1466% the |\showboxbreadth| and |\showboxdepth| parameters so that you can
1467% still change them after the loading of the package. It does,
1468% however, move them to the end of the package loading, so that they
1469% will not be affected by the |auctex| option.
1470% \begin{macrocode}
1471%<showbox>\ifPreview\else\expandafter\endinput\fi
1472%<showbox>\AtEndOfPackage{%
1473%<showbox> \showboxbreadth\maxdimen
1474%<showbox> \showboxdepth\maxdimen}
1475%<showbox>\g@addto@macro\pr@ship@end{\showbox\pr@box}
1476% \end{macrocode}
1477%
1478% \paragraph{The \texttt{tracingall} option} is for the really heavy
1479% diagnostic stuff. For the reasons mentioned above, we do not want
1480% to change the setting of the interaction mode, nor of the
1481% |tracingonline| flag. If the user wants them different, he should
1482% set them outside of the preview boxes.
1483% \begin{macrocode}
1484%<tracingall>\ifPreview\else\expandafter\endinput\fi
1485%<tracingall>\pr@addto@front\pr@ship@start{\let\tracingonline\count@
1486%<tracingall> \let\errorstopmode\@empty\tracingall}
1487% \end{macrocode}
1488%
1489% \subsection{Supporting conversions}
1490% It is not uncommon to want to use the results of |preview| as
1491% images. One possibility is to generate a flurry of EPS files with
1492% \begin{quote}
1493% |dvips -E -i -Ppdf -o| \meta{outputfile}|.000| \meta{inputfile}
1494% \end{quote}
1495% However, in case those are to be processed further into graphic
1496% image files by Ghostscript, this process is inefficient. One cannot
1497% use Ghostscript in a single run for generating the files, however,
1498% since one needs to set the page size (or full size pages will be
1499% produced). The |tightpage| option will set the page dimensions at
1500% the start of each PostScript page so that the output will be sized
1501% appropriately. That way, a single pass of Dvips followed by a
1502% single pass of Ghostscript will be sufficient for generating all
1503% images.
1504%
1505% You will have to specify the output driver to be used, either
1506% |dvips| or |pdftex|.
1507%
1508% \begin{macro}{\PreviewBorder}
1509% \begin{macro}{\PreviewBbAdjust}
1510% We start this off with the user tunable parameters which get
1511% defined even in the case of an inactive package, so that
1512% redefinitions and assignments to them will always work:
1513% \begin{macrocode}
1514%<tightpage>\ifx\PreviewBorder\@undefined
1515%<tightpage> \newdimen\PreviewBorder
1516%<tightpage> \PreviewBorder=0.50001bp
1517%<tightpage>\fi
1518%<tightpage>\ifx\PreviewBbAdjust\@undefined
1519%<tightpage> \def\PreviewBbAdjust{-\PreviewBorder -\PreviewBorder
1520%<tightpage> \PreviewBorder \PreviewBorder}
1521%<tightpage>\fi
1522% \end{macrocode}
1523% \end{macro}
1524% \end{macro}
1525% Here is stuff used for parsing this:
1526% \begin{macrocode}
1527%<tightpage>\ifPreview\else\expandafter\endinput\fi
1528%<tightpage>\def\pr@nextbb{\edef\next{\next\space\number\dimen@}%
1529%<tightpage> \expandafter\xdef\csname pr@bb@%
1530%<tightpage> \romannumeral\count@\endcsname{\the\dimen@}%
1531%<tightpage> \advance\count@\@ne\ifnum\count@<5
1532%<tightpage> \afterassignment\pr@nextbb\dimen@=\fi}
1533% \end{macrocode}
1534% And here is the stuff that we fudge into our hook. Of course, we
1535% have to do it in a box, and we start this box off with our special.
1536% There is one small consideration here: it might come before any
1537% |\AtBeginDvi| stuff containing header specials. It turns out Dvips
1538% rearranges this amicably: header code specials get transferred to
1539% the appropriate header section, anyhow, so this ensures that we come
1540% right after the bop section. We insert the 7~numbers here: the
1541% 4~bounding box adjustments, and the 3~\TeX\ box dimensions. In case
1542% the box adjustments have changed since the last time, we write them
1543% out to the console.
1544% \begin{macrocode}
1545%<tightpage>\ifnum\pr@graphicstype=\z@
1546%<tightpage> \ifcase
1547%<tightpage> \ifx\XeTeXversion\@undefined
1548%<tightpage> \ifx\pdfoutput\@undefined \@ne\fi
1549%<tightpage> \ifx\pdfoutput\relax \@ne\fi
1550%<tightpage> \ifnum\pdfoutput>\z@ \tw@\fi \@ne
1551%<tightpage> \else \thr@@\fi
1552%<tightpage> \or \ExecuteOptions{dvips}\relax
1553%<tightpage> \or \ExecuteOptions{pdftex}\relax
1554%<tightpage> \or \ExecuteOptions{xetex}\relax\fi\fi
1555%<tightpage>\global\let\pr@bbadjust\@empty
1556%<tightpage>\pr@addto@front\pr@ship@end{\begingroup
1557%<tightpage> \let\next\@gobble
1558%<tightpage> \count@\@ne\afterassignment\pr@nextbb
1559%<tightpage> \dimen@\PreviewBbAdjust
1560%<tightpage> \ifx\pr@bbadjust\next
1561%<tightpage> \else \global\let\pr@bbadjust\next
1562%<tightpage> \typeout{Preview: Tightpage \pr@bbadjust}%
1563%<tightpage> \fi\endgroup}
1564%<tightpage>\ifcase\pr@graphicstype
1565%<tightpage>\or
1566%<tightpage> \g@addto@macro\pr@ship@end{\setbox\pr@box\hbox{%
1567%<tightpage> \special{ps::\pr@bbadjust\space
1568%<tightpage> \number\ifdim\ht\pr@box>\z@ \ht\pr@box
1569%<tightpage> \else \z@
1570%<tightpage> \fi \space
1571%<tightpage> \number\ifdim\dp\pr@box>\z@ \dp\pr@box
1572%<tightpage> \else \z@
1573%<tightpage> \fi \space
1574%<tightpage> \number\ifdim\wd\pr@box>\z@ \wd\pr@box
1575%<tightpage> \else \z@
1576%<tightpage> \fi}\box\pr@box}}
1577%<tightpage>\or
1578%<tightpage> \g@addto@macro\pr@ship@end{{\dimen@\ht\pr@box
1579%<tightpage> \ifdim\dimen@<\z@ \dimen@\z@\fi
1580%<tightpage> \advance\dimen@\pr@bb@iv
1581%<tightpage> \dimen@ii=\dimen@
1582%<tightpage> \global\pdfvorigin\dimen@
1583%<tightpage> \dimen@\dp\pr@box
1584%<tightpage> \ifdim\dimen@<\z@ \dimen@\z@\fi
1585%<tightpage> \advance\dimen@-\pr@bb@ii
1586%<tightpage> \advance\dimen@\dimen@ii
1587%<tightpage> \global\pdfpageheight\dimen@
1588%<tightpage> \dimen@\wd\pr@box
1589%<tightpage> \ifdim\dimen@<\z@ \dimen@=\z@\fi
1590%<tightpage> \advance\dimen@-\pr@bb@i
1591%<tightpage> \advance\dimen@\pr@bb@iii
1592%<tightpage> \global\pdfpagewidth\dimen@
1593%<tightpage> \global\pdfhorigin-\pr@bb@i}}
1594%<tightpage>\or
1595%<tightpage> \g@addto@macro\pr@ship@end{\dimen@\ht\pr@box
1596%<tightpage> \ifdim\dimen@<\z@ \dimen@\z@\fi
1597%<tightpage> \advance\dimen@\pr@bb@iv
1598%<tightpage> \dimen@ii=\dimen@
1599%<tightpage> \voffset=-1in
1600%<tightpage> \advance\voffset\dimen@
1601%<tightpage> \advance\voffset-\ht\pr@box
1602%<tightpage> \dimen@\dp\pr@box
1603%<tightpage> \ifdim\dimen@<\z@ \dimen@\z@\fi
1604%<tightpage> \advance\dimen@-\pr@bb@ii
1605%<tightpage> \advance\dimen@\dimen@ii
1606%<tightpage> \global\pdfpageheight\dimen@
1607%<tightpage> \global\paperheight\dimen@
1608%<tightpage> \dimen@\wd\pr@box
1609%<tightpage> \ifdim\dimen@<\z@ \dimen@=\z@\fi
1610%<tightpage> \advance\dimen@-\pr@bb@i
1611%<tightpage> \advance\dimen@\pr@bb@iii
1612%<tightpage> \global\pdfpagewidth\dimen@
1613%<tightpage> \hoffset=-1in
1614%<tightpage> \advance\hoffset-\pr@bb@i
1615%<tightpage> \let\pr@offset@override\@empty}
1616%<tightpage>\fi
1617% \end{macrocode}
1618% Ok, here comes the beef. First we fish the 7~numbers from the file
1619% with |token| and convert them from \TeX~|sp| to PostScript points.
1620% \begin{macrocode}
1621%<tightpage>\ifnum\pr@graphicstype=\@ne
1622%<tightpage>\preview@delay{\AtBeginDvi{%
1623% \end{macrocode}
1624% Backwards-compatibility. Once we are certain that dvipng-1.6 or
1625% later is widely used, the three following specials can be exchanged
1626% for the simple |\special{!/preview@tightpage true def}|
1627% \begin{macrocode}
1628%<tightpage> \special{!/preview@tightpage true def (%
1629%<tightpage> compatibility PostScript comment for dvipng<=1.5 }
1630%<tightpage> \special{!userdict begin/bop-hook{%
1631%<tightpage> 7{currentfile token not{stop}if
1632%<tightpage> 65781.76 div DVImag mul}repeat
1633%<tightpage> 72 add 72 2 copy gt{exch}if 4 2 roll
1634%<tightpage> neg 2 copy lt{exch}if dup 0 gt{pop 0 exch}%
1635%<tightpage> {exch dup 0 lt{pop 0}if}ifelse 720 add exch 720 add
1636%<tightpage> 3 1 roll
1637%<tightpage> 4{5 -1 roll add 4 1 roll}repeat
1638%<tightpage> <</PageSize[5 -1 roll 6 index sub 5 -1 roll 5 index sub]%
1639%<tightpage> /PageOffset[7 -2 roll [1 1 dtransform exch]%
1640%<tightpage> {0 ge{neg}if exch}forall]>>setpagedevice%
1641%<tightpage> //bop-hook exec}bind def end}
1642%<tightpage> \special{!userdict (some extra code to avoid
1643%<tightpage> dvipng>=1.6 unknown special:
1644%<tightpage> 7{currentfile token not{stop}if 65781.76 div })) pop}
1645% \end{macrocode}
1646% The ``userdict'' at the start of the last special is also there to
1647% avoid an unknown special in dvipng<=1.6. This is the end of the
1648% backwards-compatibility code.
1649% \begin{macrocode}
1650%<tightpage> \special{!userdict begin/bop-hook{%
1651%<tightpage> preview-bop-level 0 le{%
1652%<tightpage> 7{currentfile token not{stop}if
1653%<tightpage> 65781.76 div DVImag mul}repeat
1654% \end{macrocode}
1655% Next we produce the horizontal part of the bounding box as
1656% \[ (1\mathrm{in},1\mathrm{in}) +
1657% \bigl(\min(|\wd\pr@box|,0),\max(|\wd\pr@box|,0)\bigr) \]
1658% and roll it to the bottom of the stack:
1659% \begin{macrocode}
1660%<tightpage> 72 add 72 2 copy gt{exch}if 4 2 roll
1661% \end{macrocode}
1662% Next is the vertical part of the bounding box. Depth counts in
1663% negatively, and we again take $\min$ and $\max$ of possible extents
1664% in the vertical direction, limited by 0. 720 corresponds to
1665% $10\,\mathrm{in}$ and is the famous $1\,\mathrm{in}$ distance away
1666% from the edge of letterpaper.
1667% \begin{macrocode}
1668%<tightpage> neg 2 copy lt{exch}if dup 0 gt{pop 0 exch}%
1669%<tightpage> {exch dup 0 lt{pop 0}if}ifelse 720 add exch 720 add
1670%<tightpage> 3 1 roll
1671% \end{macrocode}
1672% Ok, we now have the bounding box on the stack in the proper order
1673% llx, lly, urx, ury. We add the adjustments:
1674% \begin{macrocode}
1675%<tightpage> 4{5 -1 roll add 4 1 roll}repeat
1676% \end{macrocode}
1677% The page size is calculated as the appropriate differences, the page
1678% offset consists of the coordinates of the lower left corner, with
1679% those coordinates negated that would be reckoned positive in the
1680% device coordinate system.
1681% \begin{macrocode}
1682%<tightpage> <</PageSize[5 -1 roll 6 index sub 5 -1 roll 5 index sub]%
1683%<tightpage> /PageOffset[7 -2 roll [1 1 dtransform exch]%
1684%<tightpage> {0 ge{neg}if exch}forall]>>setpagedevice}if%
1685% \end{macrocode}
1686% So we now bind the old definition of |bop-hook| into our new
1687% definition and finish it.
1688% \begin{macrocode}
1689%<tightpage> //bop-hook exec}bind def end}}}
1690%<tightpage>\fi
1691% \end{macrocode}
1692%
1693% \subsection{The \texttt{showlabels} option}
1694% During the editing process, some people like to see the label names
1695% in their equations, figures and the like. Now if you are using
1696% Emacs for editing, and in particular \previewlatex, I'd strongly
1697% recommend that you check out the Ref\TeX\ package which pretty much
1698% obliterates the need for this kind of functionality. If you still
1699% want it, standard \LaTeX\ provides it with the |showkeys| package,
1700% and there is also the less encompassing |showlabels| package.
1701% Unfortunately, since those go to some pain not to change the page
1702% layout and spacing, they also don't change |preview|'s idea of the
1703% \TeX\ dimensions of the involved boxes.
1704%
1705% So those packages are mostly useless. So we present here an
1706% alternative hack that will get the labels through.
1707% \begin{macro}{\pr@labelbox}
1708% This works by collecting them into a separate box which we then
1709% tack to the right of the previews.
1710% \begin{macrocode}
1711%<showlabels>\ifPreview\else\expandafter\endinput\fi
1712%<showlabels>\newbox\pr@labelbox
1713% \end{macrocode}
1714% \end{macro}
1715% \begin{macro}{\pr@label}
1716% We follow up with our own definition of the \cmd{\label} macro
1717% which will be active only in previews. The original definition is
1718% stored in |\pr@@label|. |\pr@lastlabel| contains the last typeset
1719% label in order to avoid duplication in certain environments, and
1720% we keep the stuff in |\pr@labelbox|.
1721% \begin{macrocode}
1722%<showlabels>\def\pr@label#1{\pr@@label{#1}%
1723% \end{macrocode}
1724% Ok, now we generate the box, by placing the label below any existing
1725% stuff.
1726% \begin{macrocode}
1727%<showlabels> \ifpr@setbox\z@{#1}%
1728%<showlabels> \global\setbox\pr@labelbox\vbox{\unvbox\pr@labelbox
1729%<showlabels> \box\z@}\egroup\fi}
1730% \end{macrocode}
1731% \end{macro}
1732% \begin{macro}{\ifpr@setbox}
1733% |\ifpr@setbox| receives two arguments, |#1| is the box into which
1734% to set a label, |#2| is the label text itself. If a label needs
1735% to be set (if it is not a duplicate in the current box, and is
1736% nonempty, and we are in the course of typesetting and so on), we
1737% are left in a true conditional and an open group with the preset
1738% box. If nothing should be set, no group is opened, and we get
1739% into skipping to the closing of the conditional. Since
1740% |\ifpr@setbox| is a macro, you should not place the call to it
1741% into conditional text, since it will not pair up with |\fi| until
1742% being expanded.
1743%
1744% We have some trickery involved here. |\romannumeral\z@| expands
1745% to empty, and will also remove everything between the two of them
1746% that also expands to empty, like a chain of |\fi|.
1747% \begin{macrocode}
1748%<showlabels>\def\ifpr@setbox#1#2{%
1749%<showlabels> \romannumeral%
1750%<showlabels> \ifx\protect\@typeset@protect\ifpr@outer\else
1751% \end{macrocode}
1752% Ignore empty labels\dots
1753% \begin{macrocode}
1754%<showlabels> \z@\bgroup
1755%<showlabels> \protected@edef\next{#2}\@onelevel@sanitize\next
1756%<showlabels> \ifx\next\@empty\egroup\romannumeral\else
1757% \end{macrocode}
1758% and labels equal to the last one.
1759% \begin{macrocode}
1760%<showlabels> \ifx\next\pr@lastlabel\egroup\romannumeral\else
1761%<showlabels> \global\let\pr@lastlabel\next
1762%<showlabels> \setbox#1\pr@boxlabel\pr@lastlabel
1763%<showlabels> \expandafter\expandafter\romannumeral\fi\fi\fi\fi
1764%<showlabels> \z@\iffalse\iftrue\fi}
1765% \end{macrocode}
1766% \end{macro}
1767% \begin{macro}{\pr@boxlabel}
1768% Now the actual typesetting of a label box is done. We use a small
1769% typewriter font inside of a framed box (the default frame/box
1770% separating distance is a bit large).
1771% \begin{macrocode}
1772%<showlabels>\def\pr@boxlabel#1{\hbox{\normalfont
1773%<showlabels> \footnotesize\ttfamily\fboxsep0.4ex\relax\fbox{#1}}}
1774% \end{macrocode}
1775% \end{macro}
1776% \begin{macro}{\pr@maketag}
1777% And here is a version for |amsmath| equations. They look better
1778% when the label is right beside the tag, so we place it there, but
1779% augment |\box\pr@labelbox| with an appropriate placeholder.
1780% \begin{macrocode}
1781%<showlabels>\def\pr@maketag#1{\pr@@maketag{#1}%
1782%<showlabels> \ifpr@setbox\z@{\df@label}%
1783%<showlabels> \global\setbox\pr@labelbox\vbox{%
1784%<showlabels> \hrule\@width\wd\z@\@height\z@
1785%<showlabels> \unvbox\pr@labelbox}%
1786% \end{macrocode}
1787% Set the width of the box to empty so that the label placement gets
1788% not disturbed, then append it.
1789% \begin{macrocode}
1790%<showlabels> \wd\z@\z@\box\z@ \egroup\fi}
1791% \end{macrocode}
1792% \end{macro}
1793% \begin{macro}{\pr@lastlabel}
1794% Ok, here is how we activate this: we clear out box and label info
1795% \begin{macrocode}
1796%<showlabels>\g@addto@macro\pr@ship@start{%
1797%<showlabels> \global\setbox\pr@labelbox\box\voidb@x
1798%<showlabels> \xdef\pr@lastlabel{}%
1799% \end{macrocode}
1800% The definitions above are global because we might be in any amount
1801% of nesting. We then reassign the appropriate labelling macros:
1802% \begin{macrocode}
1803%<showlabels> \global\let\pr@@label\label \let\label\pr@label
1804%<showlabels> \global\let\pr@@maketag\maketag@@@
1805%<showlabels> \let\maketag@@@\pr@maketag
1806%<showlabels>}
1807% \end{macrocode}
1808% \end{macro}
1809% Now all we have to do is to add the stuff to the box in question.
1810% The stuff at the front works around a bug in |ntheorem.sty|.
1811% \begin{macrocode}
1812%<showlabels>\pr@addto@front\pr@ship@end{%
1813%<showlabels> \ifx \label\pr@label \global\let\label\pr@@label \fi
1814%<showlabels> \ifx \maketag@@@\pr@maketag
1815%<showlabels> \global\let\maketag@@@\pr@@maketag \fi
1816%<showlabels> \ifvoid\pr@labelbox
1817%<showlabels> \else \setbox\pr@box\hbox{%
1818%<showlabels> \box\pr@box\,\box\pr@labelbox}%
1819%<showlabels> \fi}
1820% \end{macrocode}
1821% \subsection{The \texttt{footnotes} option}
1822% This is rather simplistic right now. It overrides the default
1823% footnote action (which is to disable footnotes altogether for better
1824% visibility).
1825% \begin{macrocode}
1826%<footnotes>\PreviewMacro[[!]\footnote %]
1827% \end{macrocode}
1828%
1829% \section{Various driver files}
1830% The installer, in case it is missing. If it is to be used via
1831% |make|, we don't specify an installation path, since
1832% \begin{quote}
1833% |make install|
1834% \end{quote}
1835% is supposed to cater for the installation itself.
1836% \begin{macrocode}
1837%<installer> \input docstrip
1838%<installer&make> \askforoverwritefalse
1839%<installer> \generate{
1840%<installer> \file{preview.drv}{\from{preview.dtx}{driver}}
1841%<installer&!make> \usedir{tex/latex/preview}
1842%<installer> \file{preview.sty}{\from{preview.dtx}{style}
1843%<installer> \from{preview.dtx}{style,active}}
1844%<installer> \file{prauctex.def}{\from{preview.dtx}{auctex}}
1845%<installer> \file{prauctex.cfg}{\from{preview.dtx}{auccfg}}
1846%<installer> \file{prshowbox.def}{\from{preview.dtx}{showbox}}
1847%<installer> \file{prshowlabels.def}{\from{preview.dtx}{showlabels}}
1848%<installer> \file{prtracingall.def}{\from{preview.dtx}{tracingall}}
1849%<installer> \file{prtightpage.def}{\from{preview.dtx}{tightpage}}
1850%<installer> \file{prlyx.def}{\from{preview.dtx}{lyx}}
1851%<installer> \file{prcounters.def}{\from{preview.dtx}{counters}}
1852%<installer> \file{prfootnotes.def}{\from{preview.dtx}{footnotes}}
1853%<installer> }
1854%<installer> \endbatchfile
1855% \end{macrocode}
1856% And here comes the documentation driver.
1857% \begin{macrocode}
1858%<driver> \documentclass{ltxdoc}
1859%<driver> \usepackage{preview}
1860%<driver> \let\ifPreview\relax
1861%<driver> \newcommand\previewlatex{\texttt{preview-latex}}
1862%<driver> \begin{document}
1863%<driver> \DocInput{preview.dtx}
1864%<driver> \end{document}
1865% \end{macrocode}
1866% \Finale{}
1867% \iffalse
1868% Local Variables:
1869% mode: doctex
1870% TeX-master: "preview.drv"
1871% End:
1872% \fi
diff --git a/build/preview/preview.ins b/build/preview/preview.ins
deleted file mode 100644
index 1d4229d..0000000
--- a/build/preview/preview.ins
+++ /dev/null
@@ -1,44 +0,0 @@
1%%
2%% This is file `preview.ins',
3%% generated with the docstrip utility.
4%%
5%% The original source files were:
6%%
7%% preview.dtx (with options: `installer')
8%%
9%% IMPORTANT NOTICE:
10%%
11%% For the copyright see the source file.
12%%
13%% Any modified versions of this file must be renamed
14%% with new filenames distinct from preview.ins.
15%%
16%% For distribution of the original source see the terms
17%% for copying and modification in the file preview.dtx.
18%%
19%% This generated file may be distributed as long as the
20%% original source files, as listed above, are part of the
21%% same distribution. (The sources need not necessarily be
22%% in the same archive or directory.)
23%% The preview style for extracting previews from LaTeX documents.
24%% Developed as part of AUCTeX <URL:http://www.gnu.org/software/auctex>.
25 \input docstrip
26 \generate{
27 \file{preview.drv}{\from{preview.dtx}{driver}}
28 \usedir{tex/latex/preview}
29 \file{preview.sty}{\from{preview.dtx}{style}
30 \from{preview.dtx}{style,active}}
31 \file{prauctex.def}{\from{preview.dtx}{auctex}}
32 \file{prauctex.cfg}{\from{preview.dtx}{auccfg}}
33 \file{prshowbox.def}{\from{preview.dtx}{showbox}}
34 \file{prshowlabels.def}{\from{preview.dtx}{showlabels}}
35 \file{prtracingall.def}{\from{preview.dtx}{tracingall}}
36 \file{prtightpage.def}{\from{preview.dtx}{tightpage}}
37 \file{prlyx.def}{\from{preview.dtx}{lyx}}
38 \file{prcounters.def}{\from{preview.dtx}{counters}}
39 \file{prfootnotes.def}{\from{preview.dtx}{footnotes}}
40 }
41 \endbatchfile
42\endinput
43%%
44%% End of file `preview.ins'.
diff --git a/build/preview/preview.sty.do b/build/preview/preview.sty.do
deleted file mode 100644
index cf10bef..0000000
--- a/build/preview/preview.sty.do
+++ /dev/null
@@ -1,4 +0,0 @@
1redo-ifchange preview.dtx preview.ins
2KEEP="preview.dtx preview.ins preview.sty.do"
3find * -maxdepth 0 $(for x in $KEEP; do echo "-not -name $x"; done) | xargs rm >&2
4latex -interaction=batchmode preview.ins >&2
diff --git a/build/tex-filter.hs b/build/tex-filter.hs
deleted file mode 100755
index 1e2face..0000000
--- a/build/tex-filter.hs
+++ /dev/null
@@ -1,61 +0,0 @@
1#!/usr/bin/env runhaskell
2{-# LANGUAGE OverloadedStrings #-}
3
4import Text.Pandoc.JSON
5
6import Control.Monad
7import Control.Applicative
8import qualified Data.ByteString.Char8 as BS
9import Crypto.Hash
10import qualified System.IO as SIO
11import System.IO.Strict hiding (writeFile, readFile)
12import System.Directory
13import System.FilePath
14import Text.Printf
15
16import qualified Data.Text
17
18import Prelude
19
20type TeX = String
21type RawHTML = String
22
23texToPath :: FilePath -> TeX -> FilePath
24texToPath base s = base </> "tex" </> (show ( hash (BS.pack s) :: Digest SHA1))
25
26texToSVGPath :: FilePath -> TeX -> FilePath
27texToSVGPath b s = texToPath b s </> "image.svg"
28
29texToAlignPath :: FilePath -> TeX -> FilePath
30texToAlignPath b s = texToPath b s </> "vertical-align"
31
32texToExprPath :: FilePath -> TeX -> FilePath
33texToExprPath b s = texToPath b s </> "image.expr"
34
35compileToSVG :: FilePath -> MathType -> TeX -> IO RawHTML
36compileToSVG basepath t s = let tex = Data.Text.unpack $ Data.Text.strip $ Data.Text.pack s
37 path = texToPath basepath tex
38 svg_path = texToSVGPath basepath tex
39 svg_web_path = texToSVGPath "" tex
40 align_path = texToAlignPath basepath tex
41 expr_path = texToExprPath basepath tex
42
43 display DisplayMath = "\\displaystyle\n"
44 display InlineMath = ""
45 in do createDirectoryIfMissing True path
46 any (/= True) <$> mapM doesFileExist [svg_path, align_path, expr_path] >>= (flip when)
47 (do writeFile expr_path $ (display t) ++ tex
48 writeFile align_path "0")
49 alignment <- head.lines <$> readFile align_path
50 SIO.hPutStrLn SIO.stdout path
51 return $ printf "<object data=\"/%s\" type=\"image/svg+xml\" style=\"vertical-align:-%s\">%s</object>" svg_web_path alignment tex
52
53texify :: [String] -> Inline -> IO Inline
54texify [basepath] (Math t s) = do svg <- compileToSVG basepath t s
55 return $ Span ("", [classOf t], []) [RawInline (Format "html") svg]
56 where classOf DisplayMath = "display-math"
57 classOf InlineMath = "inline-math"
58texify [_] x = return x
59
60main :: IO ()
61main = toJSONFilter texify
diff --git a/clean.do b/clean.do
deleted file mode 100644
index 3444aab..0000000
--- a/clean.do
+++ /dev/null
@@ -1,4 +0,0 @@
1find -name '*.html' -not -path './nginx/*' -not -path './htdocs/*' -delete
2find -name '*.md' -not -path './posts/*' -not -name 'about.md' -delete
3find -name '*.rss' -not -path './htdocs/*' -delete
4rm tex -rf \ No newline at end of file
diff --git a/default.html.do b/default.html.do
deleted file mode 100644
index e900e4a..0000000
--- a/default.html.do
+++ /dev/null
@@ -1,15 +0,0 @@
1redo-ifchange $2.md build/tex-filter.hs build/template.html5
2
3CSS=/style.css
4
5pandoc -t json $2.md | build/tex-filter.hs "$(pwd)" \
6 | while read -r x; do
7 [[ -z "${x}" ]] && continue
8 echo $x/image.svg
9 echo $x/image.svg >&2
10 done \
11 | xargs -d '\n' redo-ifchange
12
13pandoc -S -f markdown -t json $2.md \
14 | build/tex-filter.hs "$(pwd)" \
15 | pandoc --template=build/template.html5 --base-header-level=3 --standalone --email-obfuscation=none -f json -t html5 -c $CSS >$3 2>/dev/null
diff --git a/default.nix b/default.nix
index f808b8b..d3604c3 100644
--- a/default.nix
+++ b/default.nix
@@ -1,12 +1,18 @@
1let 1let
2 pkgs = import <nixpkgs> {}; 2 pkgs = import <nixpkgs> {};
3 stdenv = pkgs.stdenv; 3 overrideCabal = drv: f: (drv.override (args: args // {
4 hs = pkgs.haskellPackages; 4 mkDerivation = drv: args.mkDerivation (drv // f drv);
5 })) // {
6 overrideScope = scope: overrideCabal (drv.overrideScope scope) f;
7 };
8 dontCheck = drv: overrideCabal drv (drv: { doCheck = false; });
5in rec { 9in rec {
6 blogEnv = stdenv.mkDerivation rec { 10 beuteltier = pkgs.stdenv.lib.overrideDerivation (
7 name = "blog-env"; 11 (pkgs.haskellngPackages.callPackage ./blog.nix {}).override (attrs: attrs // {
8 version = "1"; 12 hakyll = dontCheck pkgs.haskellngPackages.hakyll;
9 src = ./.; 13 })
10 buildInputs = [ hs.pandoc hs.pandocTypes hs.cryptohash hs.strict hs.feed ]; 14 ) (attrs : {
11 }; 15 src = ./.;
16 }
17 );
12} 18}
diff --git a/default.svg.do b/default.svg.do
deleted file mode 100644
index 76a3b0b..0000000
--- a/default.svg.do
+++ /dev/null
@@ -1,28 +0,0 @@
1redo-ifchange $2.expr build/preview/preview.sty build/preview/prtightpage.def build/preamble.tex
2INPUT=$(realpath $2.expr)
3TDIR=$(mktemp -d --tmpdir=/tmp)
4PREAMBLE=$(realpath build/preamble.tex)
5
6pushd $(dirname $2) >/dev/null
7TEXDIR=$(pwd)
8popd >/dev/null
9
10cp build/preview/preview.sty build/preview/prtightpage.def $TDIR
11
12pushd $TDIR >/dev/null
13latex -jobname=image >/dev/null <<EOF
14\input{$PREAMBLE}
15\begin{document}
16\begin{preview}
17\(
18\input{$INPUT}
19\)
20\end{preview}
21\end{document}
22EOF
23
24dvisvgm --exact --no-fonts $TDIR/image.dvi 2>&1 | sed -e '/depth=/!d;s/^.*depth=\(.*\)$/\1/' > $TEXDIR/vertical-align
25cat $TDIR/image.svg
26popd >/dev/null
27
28rm -rf $TDIR \ No newline at end of file
diff --git a/do b/do
deleted file mode 100755
index 5f20bb8..0000000
--- a/do
+++ /dev/null
@@ -1,177 +0,0 @@
1#!/bin/sh
2#
3# A minimal alternative to djb redo that doesn't support incremental builds.
4# For the full version, visit http://github.com/apenwarr/redo
5#
6# The author disclaims copyright to this source file and hereby places it in
7# the public domain. (2010 12 14)
8#
9
10# By default, no output coloring.
11green=""
12bold=""
13plain=""
14
15if [ -n "$TERM" -a "$TERM" != "dumb" ] && tty <&2 >/dev/null 2>&1; then
16 green="$(printf '\033[32m')"
17 bold="$(printf '\033[1m')"
18 plain="$(printf '\033[m')"
19fi
20
21_dirsplit()
22{
23 base=${1##*/}
24 dir=${1%$base}
25}
26
27dirname()
28(
29 _dirsplit "$1"
30 dir=${dir%/}
31 echo "${dir:-.}"
32)
33
34_dirsplit "$0"
35export REDO=$(cd "${dir:-.}" && echo "$PWD/$base")
36
37DO_TOP=
38if [ -z "$DO_BUILT" ]; then
39 DO_TOP=1
40 [ -n "$*" ] || set all # only toplevel redo has a default target
41 export DO_BUILT=$PWD/.do_built
42 : >>"$DO_BUILT"
43 echo "Removing previously built files..." >&2
44 sort -u "$DO_BUILT" | tee "$DO_BUILT.new" |
45 while read f; do printf "%s\0%s.did\0" "$f" "$f"; done |
46 xargs -0 rm -f 2>/dev/null
47 mv "$DO_BUILT.new" "$DO_BUILT"
48 DO_PATH=$DO_BUILT.dir
49 export PATH=$DO_PATH:$PATH
50 rm -rf "$DO_PATH"
51 mkdir "$DO_PATH"
52 for d in redo redo-ifchange; do
53 ln -s "$REDO" "$DO_PATH/$d";
54 done
55 [ -e /bin/true ] && TRUE=/bin/true || TRUE=/usr/bin/true
56 for d in redo-ifcreate redo-stamp redo-always; do
57 ln -s $TRUE "$DO_PATH/$d";
58 done
59fi
60
61
62_find_dofile_pwd()
63{
64 dofile=default.$1.do
65 while :; do
66 dofile=default.${dofile#default.*.}
67 [ -e "$dofile" -o "$dofile" = default.do ] && break
68 done
69 ext=${dofile#default}
70 ext=${ext%.do}
71 base=${1%$ext}
72}
73
74
75_find_dofile()
76{
77 local prefix=
78 while :; do
79 _find_dofile_pwd "$1"
80 [ -e "$dofile" ] && break
81 [ "$PWD" = "/" ] && break
82 target=${PWD##*/}/$target
83 tmp=${PWD##*/}/$tmp
84 prefix=${PWD##*/}/$prefix
85 cd ..
86 done
87 base=$prefix$base
88}
89
90
91_run_dofile()
92{
93 export DO_DEPTH="$DO_DEPTH "
94 export REDO_TARGET=$PWD/$target
95 local line1
96 set -e
97 read line1 <"$PWD/$dofile" || true
98 cmd=${line1#"#!/"}
99 if [ "$cmd" != "$line1" ]; then
100 /$cmd "$PWD/$dofile" "$@" >"$tmp.tmp2"
101 else
102 :; . "$PWD/$dofile" >"$tmp.tmp2"
103 fi
104}
105
106
107_do()
108{
109 local dir=$1 target=$2 tmp=$3
110 if [ ! -e "$target" ] || [ -d "$target" -a ! -e "$target.did" ]; then
111 printf '%sdo %s%s%s%s\n' \
112 "$green" "$DO_DEPTH" "$bold" "$dir$target" "$plain" >&2
113 echo "$PWD/$target" >>"$DO_BUILT"
114 dofile=$target.do
115 base=$target
116 ext=
117 [ -e "$target.do" ] || _find_dofile "$target"
118 if [ ! -e "$dofile" ]; then
119 echo "do: $target: no .do file" >&2
120 return 1
121 fi
122 [ ! -e "$DO_BUILT" ] || [ ! -d "$(dirname "$target")" ] ||
123 : >>"$target.did"
124 ( _run_dofile "$target" "$base" "$tmp.tmp" )
125 rv=$?
126 if [ $rv != 0 ]; then
127 printf "do: %s%s\n" "$DO_DEPTH" \
128 "$dir$target: got exit code $rv" >&2
129 rm -f "$tmp.tmp" "$tmp.tmp2"
130 return $rv
131 fi
132 mv "$tmp.tmp" "$target" 2>/dev/null ||
133 ! test -s "$tmp.tmp2" ||
134 mv "$tmp.tmp2" "$target" 2>/dev/null
135 rm -f "$tmp.tmp2"
136 else
137 echo "do $DO_DEPTH$target exists." >&2
138 fi
139}
140
141
142# Make corrections for directories that don't actually exist yet.
143_dir_shovel()
144{
145 local dir base
146 xdir=$1 xbase=$2 xbasetmp=$2
147 while [ ! -d "$xdir" -a -n "$xdir" ]; do
148 _dirsplit "${xdir%/}"
149 xbasetmp=${base}__$xbase
150 xdir=$dir xbase=$base/$xbase
151 echo "xbasetmp='$xbasetmp'" >&2
152 done
153}
154
155
156_redo()
157{
158 set +e
159 for i in "$@"; do
160 _dirsplit "$i"
161 _dir_shovel "$dir" "$base"
162 dir=$xdir base=$xbase basetmp=$xbasetmp
163 ( cd "$dir" && _do "$dir" "$base" "$basetmp" )
164 [ "$?" = 0 ] || return 1
165 done
166}
167
168
169_redo "$@"
170[ "$?" = 0 ] || exit 1
171
172if [ -n "$DO_TOP" ]; then
173 echo "Removing stamp files..." >&2
174 [ ! -e "$DO_BUILT" ] ||
175 while read f; do printf "%s.did\0" "$f"; done <"$DO_BUILT" |
176 xargs -0 rm -f 2>/dev/null
177fi
diff --git a/getopts_long.sh b/getopts_long.sh
deleted file mode 100644
index ce2f7f0..0000000
--- a/getopts_long.sh
+++ /dev/null
@@ -1,701 +0,0 @@
1#! /bin/echo Usage:.
2#
3# getopts_long -- POSIX shell getopts with GNU-style long option support
4#
5# Copyright 2005-2009 Stephane Chazelas <stephane_chazelas@yahoo.fr>
6#
7# Permission to use, copy, modify, distribute, and sell this software and
8# its documentation for any purpose is hereby granted without fee, provided
9# that the above copyright notice appear in all copies and that both that
10# copyright notice and this permission notice appear in supporting
11# documentation. No representations are made about the suitability of this
12# software for any purpose. It is provided "as is" without express or
13# implied warranty.
14
15# History:
16# 2005 ?? - 1.0
17# first version
18# 2009-08-12 - 1.1
19# thanks to ujqm8360@netwtc.net for helping fix a few bugs:
20# - -ab x where -b accepts arguments wasn't handled properly. Also,
21# $OPTLIND wasn't set properly (at least not the same way as most
22# getopts implementation do).
23# - The handling of ambiguous long options was incorrect.
24
25getopts_long() {
26 # args: shortopts, var, [name, type]*, "", "$@"
27 #
28 # getopts_long parses command line arguments. It works like the
29 # getopts shell built-in command except that it also recognises long
30 # options a la GNU.
31 #
32 # You must provide getopts_long with the list of supported single
33 # letter options in the same format as getopts', followed by the
34 # variable name you want getopts_long to return the current processed
35 # option in, followed by the list of long option names (without the
36 # leading "--") and types (0 or no_argument, 1 or required_argument,
37 # 2 or optional_argument). The end of the long option specification
38 # is indicated by an empty argument. Then follows the list of
39 # arguments to be parsed.
40 #
41 # The $OPTLIND variable must be set to 1 before the first call of the
42 # getopts_long function to process a given list of arguments.
43 #
44 # getopts_long returns the value of the current option in the variable
45 # whose name is provided as its second argument (be careful to avoid
46 # variables that have a special signification to getopts_long or the
47 # shell or any other tool you may call from your script). If the
48 # current option is a single letter option, then it is returned
49 # without the leading "-". If it's a long option (possibly
50 # abbreviated), then the full name of the option (without the leading
51 # "--") is returned. If the option has an argument, then it is stored
52 # in the $OPTLARG variable. If the current option is not recognised,
53 # or if it is provided with an argument while it is not expecting one
54 # (as in --opt=value) or if it is not provided with an argument while
55 # it is expecting one, or if the option is so abbreviated that it is
56 # impossible to identify the option uniquely, then:
57 # - if the short option specifications begin with ":", getopts_long
58 # returns ":" in the output variable and $OPTLARG contains the
59 # faulty option name (in full except in the case of the ambiguous
60 # or bad option) and $OPTLERR contains the error message.
61 # - if not, then getopts_long behaves the same as above except that
62 # it returns "?" instead of ":", leaves $OPTLARG unset and
63 # displays the error message on stderr.
64 #
65 # The exit status of getopts_long is 0 unless the end of options is
66 # reached or an error is encountered in the syntax of the getopts_long
67 # call.
68 #
69 # After getopts_long has finished processing the options, $OPTLIND
70 # contains the index of the first non-option argument or $# + 1 if
71 # there's no non-option argument.
72 #
73 # The "=" character is not allowed in a long option name. Any other
74 # character is. "-" and ":" are not allowed as short option names. Any
75 # other character is. If a short option appears more than once in the
76 # specification, the one with the greatest number of ":"s following it
77 # is retained. If a long option name is provided more than once, only
78 # the first one is taken into account. Note that if you have both a -a
79 # and --a option, there's no way to differentiate them. Beside the
80 # $OPTLIND, $OPTLARG, and $OPTLERR, getopts_long uses the $OPTLPENDING
81 # variable to hold the remaining options to be processed for arguments
82 # with several one-letter options. That variable shouldn't be used
83 # anywhere else in your script. Those 4 variables are the only ones
84 # getopts_long may modify.
85 #
86 # Dependency: only POSIX utilities are called by that function. They
87 # are "set", "unset", "shift", "break", "return", "eval", "command",
88 # ":", "printf" and "[". Those are generally built in the POSIX
89 # shells. Only "printf" has been known not to be in some old versions
90 # of bash, zsh or ash based shells.
91 #
92 # Differences with the POSIX getopts:
93 # - if an error is detected during the parsing of command line
94 # arguments, the error message is stored in the $OPTLERR variable
95 # and if the first character of optstring is ':', ':' is returned in
96 # any case.
97 # - in the single-letter option specification, if a letter is
98 # followed by 2 colons ("::"), then the option can have an optional
99 # argument as in GNU getopt(3). In that case, the argument must
100 # directly follow the option as in -oarg (not -o arg).
101 # - there must be an empty argument to mark the end of the option
102 # specification.
103 # - long options starting with "--" are supported.
104 #
105 # Differences with GNU getopt_long(3):
106 # - getopts_long doesn't allow options to be interspersed with other
107 # arguments (as if POSIXLY_CORRECT was set for GNU getopt_long(3))
108 # - there's no linkage of any sort between the short and long
109 # options. The caller is responsible of that (see example below).
110 #
111 # Compatibility:
112 # getopts_long code is (hopefully) POSIX.2/SUSv3 compliant. It won't
113 # work with the Bourne/SystemV shell. Use /usr/xpg4/bin/sh or ksh or
114 # bash on Solaris.
115 # It has been tested successfully with:
116 # - bash 3.0 (patch level 16) on Cygwin
117 # - zsh 4.2.4 on Solaris 2.7
118 # - /usr/xpg4/bin/sh (same as /usr/bin/ksh) (ksh88i) on Solaris 2.7
119 # - /usr/dt/bin/dtksh (ksh93d) on Solaris 2.7
120 # - /usr/bin/ksh (pdksh 5.2.14) on Linux
121 # - zsh 3.0.6 on Solaris 2.8
122 # - bash 2.0.3 on Solaris 2.8
123 # - dash 0.5.2 on Linux
124 # - bash 2.05b (patch level 0) on Linux
125 # - ksh93p and ksh93q on Linux (ksh93t+ crashes)
126 #
127 # It is known to fail with those non-POSIX compliant shells:
128 # - /bin/sh on Solaris
129 # - /usr/bin/sh on Cygwin
130 # - bash 1.x
131 #
132 # Bugs:
133 # please report them to <stephane_chazelas@yahoo.fr>
134 #
135 # Example:
136 #
137 # verbose=false opt_bar=false bar=default_bar foo=default_foo
138 # opt_s=false opt_long=false
139 # OPTLIND=1
140 # while getopts_long :sf:b::vh opt \
141 # long 0 \
142 # foo required_argument \
143 # bar 2 \
144 # verbose no_argument \
145 # help 0 "" "$@"
146 # do
147 # case "$opt" in
148 # s) opt_s=true;;
149 # long) opt_long=true;;
150 # v|verbose) verbose=true;;
151 # h|help) usage; exit 0;;
152 # f|foo) foo=$OPTLARG;;
153 # b|bar) bar=${OPTLARG-$bar};;
154 # :) printf >&2 '%s: %s\n' "${0##*/}" "$OPTLERR"
155 # usage
156 # exit 1;;
157 # esac
158 # done
159 # shift "$(($OPTLIND - 1))"
160 # # process the remaining arguments
161
162 [ -n "${ZSH_VERSION+z}" ] && emulate -L sh
163
164 unset OPTLERR OPTLARG || :
165
166 case "$OPTLIND" in
167 "" | 0 | *[!0-9]*)
168 # First time in the loop. Initialise the parameters.
169 OPTLIND=1
170 OPTLPENDING=
171 ;;
172 esac
173
174 if [ "$#" -lt 2 ]; then
175 printf >&2 'getopts_long: not enough arguments\n'
176 return 1
177 fi
178
179 # validate variable name. Need to fix locale for character ranges.
180 LC_ALL=C command eval '
181 case "$2" in
182 *[!a-zA-Z_0-9]*|""|[0-9]*)
183 printf >&2 "getopts_long: invalid variable name: \`%s'\''\n" "$2"
184 return 1
185 ;;
186 esac'
187
188 # validate short option specification
189 case "$1" in
190 ::*|*:::*|*-*)
191 printf >&2 "getopts_long: invalid option specification: \`%s'\n" "$1"
192 return 1
193 ;;
194 esac
195
196 # validate long option specifications
197
198 # POSIX shells only have $1, $2... as local variables, hence the
199 # extensive use of "set" in that function.
200
201 set 4 "$@"
202 while :; do
203 if
204 [ "$1" -gt "$#" ] || {
205 eval 'set -- "${'"$1"'}" "$@"'
206 [ -n "$1" ] || break
207 [ "$(($2 + 2))" -gt "$#" ]
208 }
209 then
210 printf >&2 "getopts_long: long option specifications must end in an empty argument\n"
211 return 1
212 fi
213 eval 'set -- "${'"$(($2 + 2))"'}" "$@"'
214 # $1 = type, $2 = name, $3 = $@
215 case "$2" in
216 *=*)
217 printf >&2 "getopts_long: invalid long option name: \`%s'\n" "$2"
218 return 1
219 ;;
220 esac
221 case "$1" in
222 0 | no_argument) ;;
223 1 | required_argument) ;;
224 2 | optional_argument) ;;
225 *)
226 printf >&2 "getopts_long: invalid long option type: \`%s'\n" "$1"
227 return 1
228 ;;
229 esac
230 eval "shift 3; set $(($3 + 2))"' "$@"'
231 done
232 shift
233
234 eval "shift; set $(($1 + $OPTLIND))"' "$@"'
235
236 # unless there are pending short options to be processed (in
237 # $OPTLPENDING), the current option is now in ${$1}
238
239 if [ -z "$OPTLPENDING" ]; then
240 [ "$1" -le "$#" ] || return 1
241 eval 'set -- "${'"$1"'}" "$@"'
242
243 case "$1" in
244 --)
245 OPTLIND=$(($OPTLIND + 1))
246 return 1
247 ;;
248 --*)
249 OPTLIND=$(($OPTLIND + 1))
250 ;;
251 -?*)
252 OPTLPENDING="${1#-}"
253 shift
254 ;;
255 *)
256 return 1
257 ;;
258 esac
259 fi
260
261 if [ -n "$OPTLPENDING" ]; then
262 # WA for zsh and bash 2.03 bugs:
263 OPTLARG=${OPTLPENDING%"${OPTLPENDING#?}"}
264 set -- "$OPTLARG" "$@"
265 OPTLPENDING="${OPTLPENDING#?}"
266 unset OPTLARG
267
268 # $1 = current option = ${$2+1}, $3 = $@
269
270 [ -n "$OPTLPENDING" ] ||
271 OPTLIND=$(($OPTLIND + 1))
272
273 case "$1" in
274 [-:])
275 OPTLERR="bad option: \`-$1'"
276 case "$3" in
277 :*)
278 eval "$4=:"
279 OPTLARG="$1"
280 ;;
281 *)
282 printf >&2 '%s\n' "$OPTLERR"
283 eval "$4='?'"
284 ;;
285 esac
286 ;;
287
288 *)
289 case "$3" in
290 *"$1"::*) # optional argument
291 eval "$4=\"\$1\""
292 if [ -n "$OPTLPENDING" ]; then
293 # take the argument from $OPTLPENDING if any
294 OPTLARG="$OPTLPENDING"
295 OPTLPENDING=
296 OPTLIND=$(($OPTLIND + 1))
297 fi
298 ;;
299
300 *"$1":*) # required argument
301 if [ -n "$OPTLPENDING" ]; then
302 # take the argument from $OPTLPENDING if any
303 OPTLARG="$OPTLPENDING"
304 eval "$4=\"\$1\""
305 OPTLPENDING=
306 OPTLIND=$(($OPTLIND + 1))
307 else
308 # take the argument from the next argument
309 if [ "$(($2 + 2))" -gt "$#" ]; then
310 OPTLERR="option \`-$1' requires an argument"
311 case "$3" in
312 :*)
313 eval "$4=:"
314 OPTLARG="$1"
315 ;;
316 *)
317 printf >&2 '%s\n' "$OPTLERR"
318 eval "$4='?'"
319 ;;
320 esac
321 else
322 OPTLIND=$(($OPTLIND + 1))
323 eval "OPTLARG=\"\${$(($2 + 2))}\""
324 eval "$4=\"\$1\""
325 fi
326 fi
327 ;;
328
329 *"$1"*) # no argument
330 eval "$4=\"\$1\""
331 ;;
332 *)
333 OPTLERR="bad option: \`-$1'"
334 case "$3" in
335 :*)
336 eval "$4=:"
337 OPTLARG="$1"
338 ;;
339 *)
340 printf >&2 '%s\n' "$OPTLERR"
341 eval "$4='?'"
342 ;;
343 esac
344 ;;
345 esac
346 ;;
347 esac
348 else # long option
349
350 # remove the leading "--"
351 OPTLPENDING="$1"
352 shift
353 set 6 "${OPTLPENDING#--}" "$@"
354 OPTLPENDING=
355
356 while
357 eval 'set -- "${'"$1"'}" "$@"'
358 [ -n "$1" ]
359 do
360 # $1 = option name = ${$2+1}, $3 => given option = ${$4+3}, $5 = $@
361
362 case "${3%%=*}" in
363 "$1")
364 OPTLPENDING=EXACT
365 break;;
366 esac
367
368 # try to see if the current option can be seen as an abbreviation.
369 case "$1" in
370 "${3%%=*}"*)
371 if [ -n "$OPTLPENDING" ]; then
372 [ "$OPTLPENDING" = AMBIGUOUS ] || eval '[ "${'"$(($OPTLPENDING + 1))"'}" = "$1" ]' ||
373 OPTLPENDING=AMBIGUOUS
374 # there was another different option matching the current
375 # option. The eval thing is in case one option is provided
376 # twice in the specifications which is OK as per the
377 # documentation above
378 else
379 OPTLPENDING="$2"
380 fi
381 ;;
382 esac
383 eval "shift 2; set $(($2 + 2)) "'"$@"'
384 done
385
386 case "$OPTLPENDING" in
387 AMBIGUOUS)
388 OPTLERR="option \`--${3%%=*}' is ambiguous"
389 case "$5" in
390 :*)
391 eval "$6=:"
392 OPTLARG="${3%%=*}"
393 ;;
394 *)
395 printf >&2 '%s\n' "$OPTLERR"
396 eval "$6='?'"
397 ;;
398 esac
399 OPTLPENDING=
400 return 0
401 ;;
402 EXACT)
403 eval 'set "${'"$(($2 + 2))"'}" "$@"'
404 ;;
405 "")
406 OPTLERR="bad option: \`--${3%%=*}'"
407 case "$5" in
408 :*)
409 eval "$6=:"
410 OPTLARG="${3%%=*}"
411 ;;
412 *)
413 printf >&2 '%s\n' "$OPTLERR"
414 eval "$6='?'"
415 ;;
416 esac
417 OPTLPENDING=
418 return 0
419 ;;
420 *)
421 # we've got an abbreviated long option.
422 shift
423 eval 'set "${'"$(($OPTLPENDING + 1))"'}" "${'"$OPTLPENDING"'}" "$@"'
424 ;;
425 esac
426
427 OPTLPENDING=
428
429 # $1 = option type, $2 = option name, $3 unused,
430 # $4 = given option = ${$5+4}, $6 = $@
431
432 case "$4" in
433 *=*)
434 case "$1" in
435 1 | required_argument | 2 | optional_argument)
436 eval "$7=\"\$2\""
437 OPTLARG="${4#*=}"
438 ;;
439 *)
440 OPTLERR="option \`--$2' doesn't allow an argument"
441 case "$6" in
442 :*)
443 eval "$7=:"
444 OPTLARG="$2"
445 ;;
446 *)
447 printf >&2 '%s\n' "$OPTLERR"
448 eval "$7='?'"
449 ;;
450 esac
451 ;;
452 esac
453 ;;
454
455 *)
456 case "$1" in
457 1 | required_argument)
458 if [ "$(($5 + 5))" -gt "$#" ]; then
459 OPTLERR="option \`--$2' requires an argument"
460 case "$6" in
461 :*)
462 eval "$7=:"
463 OPTLARG="$2"
464 ;;
465 *)
466 printf >&2 '%s\n' "$OPTLERR"
467 eval "$7='?'"
468 ;;
469 esac
470 else
471 OPTLIND=$(($OPTLIND + 1))
472 eval "OPTLARG=\"\${$(($5 + 5))}\""
473 eval "$7=\"\$2\""
474 fi
475 ;;
476 *)
477 # optional argument (but obviously not provided) or no
478 # argument
479 eval "$7=\"\$2\""
480 ;;
481 esac
482 ;;
483 esac
484 fi
485 return 0
486}
487
488# testing code
489if [ -n "$test_getopts_long" ]; then
490test_getopts_long() {
491 expected="$1" had=
492 shift
493 OPTLIND=1
494
495 while err="$(set +x;getopts_long "$@" 2>&1 > /dev/null)"
496 getopts_long "$@" 2> /dev/null; do
497 eval "opt=\"\$$2\""
498 had="$had|$opt@${OPTLARG-unset}@${OPTLIND-unset}@${OPTLERR-unset}@$err"
499 done
500 had="$had|${OPTLIND-unset}|$err"
501
502 if [ "$had" = "$expected" ]; then
503 echo PASS
504 else
505 echo FAIL
506 printf 'Expected: %s\n Got: %s\n' "$expected" "$had"
507 fi
508}
509while IFS= read -r c && IFS= read -r e; do
510 printf '+ %-72s ' "$c"
511 #set -x
512 eval "test_getopts_long \"\$e\" $c"
513done << \EOF
514: a
515|1|getopts_long: long option specifications must end in an empty argument
516:a opt "" -a
517|a@unset@2@unset@|2|
518:a opt "" -a b
519|a@unset@2@unset@|2|
520:a opt "" -a -a
521|a@unset@2@unset@|a@unset@3@unset@|3|
522:a opt "" -ab
523|a@unset@1@unset@|:@b@2@bad option: `-b'@|2|
524:a: opt "" -ab
525|a@b@2@unset@|2|
526:a: opt "" -a b
527|a@b@3@unset@|3|
528:a: opt "" -a -a
529|a@-a@3@unset@|3|
530:a: opt "" -a
531|:@a@2@option `-a' requires an argument@|2|
532:a:: opt "" -a
533|a@unset@2@unset@|2|
534:a:: opt "" -ab
535|a@b@2@unset@|2|
536:a:: opt "" -a b
537|a@unset@2@unset@|2|
538:ab: opt "" -ab c
539|a@unset@1@unset@|b@c@3@unset@|3|
540:a:: opt "" -a -a
541|a@unset@2@unset@|a@unset@3@unset@|3|
542:a:: opt "" -:a:
543|:@:@1@bad option: `-:'@|a@:@2@unset@|2|
544:= opt ""
545|1|
546:: opt ""
547|1|getopts_long: invalid option specification: `::'
548: opt ""
549|1|
550:a:a opt "" -a
551|:@a@2@option `-a' requires an argument@|2|
552:a::a opt "" -a
553|a@unset@2@unset@|2|
554:ab:c:: opt "" -abc -cba -bac
555|a@unset@1@unset@|b@c@2@unset@|c@ba@3@unset@|b@ac@4@unset@|4|
556: opt abc 0 "" --abc
557|abc@unset@2@unset@|2|
558: opt abc no_argument "" --abc
559|abc@unset@2@unset@|2|
560: opt abc no_argument "" --abc=foo
561|:@abc@2@option `--abc' doesn't allow an argument@|2|
562: opt abc no_argument "" --abc foo
563|abc@unset@2@unset@|2|
564: opt abc 1 "" --abc=foo
565|abc@foo@2@unset@|2|
566: opt abc required_argument "" --abc foo
567|abc@foo@3@unset@|3|
568: opt abc required_argument "" --abc=
569|abc@@2@unset@|2|
570: opt abc required_argument "" --abc
571|:@abc@2@option `--abc' requires an argument@|2|
572: opt abc 2 "" --abc
573|abc@unset@2@unset@|2|
574: opt abc optional_argument "" --abc=
575|abc@@2@unset@|2|
576: opt abc optional_argument "" --abc=foo
577|abc@foo@2@unset@|2|
578: opt abc optional_argument "" --abc --abc
579|abc@unset@2@unset@|abc@unset@3@unset@|3|
580: opt abc 0 abcd 0 "" --abc
581|abc@unset@2@unset@|2|
582: opt abc 0 abd 0 "" --ab
583|:@ab@2@option `--ab' is ambiguous@|2|
584: opt abc 0 abcd 0 "" --ab
585|:@ab@2@option `--ab' is ambiguous@|2|
586: opt abc 0 abc 1 "" --ab
587|abc@unset@2@unset@|2|
588: opt abc 0 abc 1 "" --abc
589|abc@unset@2@unset@|2|
590: opt abc 0 abc 1 "" --ab
591|abc@unset@2@unset@|2|
592: opt abc 0 acd 0 "" --ab
593|abc@unset@2@unset@|2|
594:abc:d:e::f:: opt ab 0 ac 1 bc 2 cd 1 cde 2 "" -abcdef -a -f -c --a --a= --b=foo -fg
595|a@unset@1@unset@|b@unset@1@unset@|c@def@2@unset@|a@unset@3@unset@|f@unset@4@unset@|c@--a@6@unset@|:@a@7@option `--a' is ambiguous@|bc@foo@8@unset@|f@g@9@unset@|9|
596a opt "" -a
597|a@unset@2@unset@|2|
598a opt "" -a b
599|a@unset@2@unset@|2|
600a opt "" -a -a
601|a@unset@2@unset@|a@unset@3@unset@|3|
602a opt "" -ab
603|a@unset@1@unset@|?@unset@2@bad option: `-b'@bad option: `-b'|2|
604a: opt "" -ab
605|a@b@2@unset@|2|
606a: opt "" -a b
607|a@b@3@unset@|3|
608a: opt "" -a -a
609|a@-a@3@unset@|3|
610a: opt "" -a
611|?@unset@2@option `-a' requires an argument@option `-a' requires an argument|2|
612a:: opt "" -a
613|a@unset@2@unset@|2|
614a:: opt "" -ab
615|a@b@2@unset@|2|
616a:: opt "" -a b
617|a@unset@2@unset@|2|
618a:: opt "" -a -a
619|a@unset@2@unset@|a@unset@3@unset@|3|
620a:: opt "" -:a:
621|?@unset@1@bad option: `-:'@bad option: `-:'|a@:@2@unset@|2|
622= opt ""
623|1|
624: opt ""
625|1|
626'' opt ""
627|1|
628a:a opt "" -a
629|?@unset@2@option `-a' requires an argument@option `-a' requires an argument|2|
630a::a opt "" -a
631|a@unset@2@unset@|2|
632ab:c:: opt "" -abc -cba -bac
633|a@unset@1@unset@|b@c@2@unset@|c@ba@3@unset@|b@ac@4@unset@|4|
634'' opt abc 0 "" --abc
635|abc@unset@2@unset@|2|
636'' opt abc no_argument "" --abc
637|abc@unset@2@unset@|2|
638'' opt abc no_argument "" --abc=foo
639|?@unset@2@option `--abc' doesn't allow an argument@option `--abc' doesn't allow an argument|2|
640'' opt abc no_argument "" --abc foo
641|abc@unset@2@unset@|2|
642'' opt abc 1 "" --abc=foo
643|abc@foo@2@unset@|2|
644'' opt abc required_argument "" --abc foo
645|abc@foo@3@unset@|3|
646'' opt abc required_argument "" --abc=
647|abc@@2@unset@|2|
648'' opt abc required_argument "" --abc
649|?@unset@2@option `--abc' requires an argument@option `--abc' requires an argument|2|
650'' opt abc 2 "" --abc
651|abc@unset@2@unset@|2|
652'' opt abc optional_argument "" --abc=
653|abc@@2@unset@|2|
654'' opt abc optional_argument "" --abc=foo
655|abc@foo@2@unset@|2|
656'' opt abc optional_argument "" --abc --abc
657|abc@unset@2@unset@|abc@unset@3@unset@|3|
658'' opt abc 0 abcd 0 "" --abc
659|abc@unset@2@unset@|2|
660'' opt abc 0 abd 0 "" --ab
661|?@unset@2@option `--ab' is ambiguous@option `--ab' is ambiguous|2|
662'' opt abc 0 abcd 0 "" --ab
663|?@unset@2@option `--ab' is ambiguous@option `--ab' is ambiguous|2|
664'' opt abc 0 abc 1 "" --ab
665|abc@unset@2@unset@|2|
666'' opt abc 0 abc 1 "" --abc
667|abc@unset@2@unset@|2|
668'' opt abc 0 abc 1 "" --ab
669|abc@unset@2@unset@|2|
670'' opt abc 0 acd 0 "" --ab
671|abc@unset@2@unset@|2|
672abc:d:e::f:: opt ab 0 ac 1 bc 2 cd 1 cde 2 "" -abcdef -a -f -c --a --a= --b=foo -fg
673|a@unset@1@unset@|b@unset@1@unset@|c@def@2@unset@|a@unset@3@unset@|f@unset@4@unset@|c@--a@6@unset@|?@unset@7@option `--a' is ambiguous@option `--a' is ambiguous|bc@foo@8@unset@|f@g@9@unset@|9|
674: '' '' a
675|1|getopts_long: invalid variable name: `'
676: 1a ''
677|1|getopts_long: invalid variable name: `1a'
678- a
679|1|getopts_long: invalid option specification: `-'
680:a::a:abcd o ab 1 abc 1 abd 1 abe 1 abc 2 '' -aa --ab 1 --abc
681|a@a@2@unset@|ab@1@4@unset@|:@abc@5@option `--abc' requires an argument@|5|
682:
683|1|getopts_long: not enough arguments
684'\[$' o -- 0 ' ' 1 '#' required_argument '' '-\\\[$' --\ =a --\#=\$\$
685|\@unset@1@unset@|\@unset@1@unset@|\@unset@1@unset@|[@unset@1@unset@|$@unset@2@unset@| @a@3@unset@|#@$$@4@unset@|4|
686: o a 1 b 2 c
687|1|getopts_long: long option specifications must end in an empty argument
688: o a 1 b 2
689|1|getopts_long: long option specifications must end in an empty argument
690: o a 1 b 2 c 3 '' --c
691|1|getopts_long: invalid long option type: `3'
692": " o " " 1 '' "- " "-- =1"
693| @unset@1@unset@| @unset@2@unset@| @1@3@unset@|3|
694: o a 1 '' --c
695|:@c@2@bad option: `--c'@|2|
696: o a 1 '' --c=foo
697|:@c@2@bad option: `--c'@|2|
698: o ab 1 ac 1 ad 1 a 1 '' --a=1
699|a@1@2@unset@|2|
700EOF
701fi
diff --git a/htdocs.do b/htdocs.do
deleted file mode 100644
index 280bfee..0000000
--- a/htdocs.do
+++ /dev/null
@@ -1,3 +0,0 @@
1redo-ifchange all
2find . \( -name '*.html' -or -name '*.css' -or -name '*.svg' -or -name '*.rss' \) -and -not \( -path '*/.cabal-sandbox/*' -or -path '*/htdocs/*' -or -path '*/build/*' \) -print0 | \
3xargs -0 -I '{}' -- rsync -Rav --delete '{}' htdocs >&2
diff --git a/index.md.do b/index.md.do
deleted file mode 100644
index 3155cb7..0000000
--- a/index.md.do
+++ /dev/null
@@ -1,27 +0,0 @@
1#!/usr/bin/env bash
2
3LISTS=()
4while read -r -d $'\0'; do
5 LISTS+=("$REPLY")
6done < <(find lists -maxdepth 1 -mindepth 1 -type d -not -name '.*' -print0 | sort -z)
7
8for x in "${LISTS[@]}"; do
9 printf "%s.html\0" "$x"
10 printf "rss/%s.rss\0" "$(basename $x)"
11done | xargs -r -0 redo-ifchange
12
13cat <<EOF
14% Index
15
16This is a blog.
17It contains things.
18Send things to <blog@dirty-haskell.org> if you so choose.
19
20EOF
21
22for x in "${LISTS[@]}"; do
23 printf "* [%s](%s) ([RSS](rss/%s))\n" "$(<$x/title)" "$x.html" "$(basename $x).rss"
24 while read -r -d $'\n'; do
25 printf " %s\n" "$REPLY"
26 done < "$x/preview"
27done
diff --git a/lists.sh b/lists.sh
deleted file mode 100755
index c07870a..0000000
--- a/lists.sh
+++ /dev/null
@@ -1,66 +0,0 @@
1#!/usr/bin/env bash
2
3shopt -s extglob nullglob
4
5. ./getopts_long.sh
6
7find_lists() {
8 LISTS=()
9 while read -r -d $'\0'; do
10 local list=$(realpath --relative-to=. "$REPLY")
11 LISTS+=("$list")
12 done < <(find lists -maxdepth 1 -mindepth 1 -type d -not -name '.*' -print0 | sort -z)
13}
14
15find_posts() {
16 local list="$1"
17 shift 1
18
19 POSTS=()
20 for p in "$list"/!(*[!0-9]*); do
21 POSTS+=( "$p" )
22 done
23}
24
25print_lists() {
26 find_lists
27 for x in "${LISTS[@]}"; do
28 printf "%s: %s\n" "$x" "$(<$x/title)"
29 done
30}
31
32print_posts() {
33 find_posts "$1"
34 for p in "${POSTS[@]}"; do
35 local post=$(readlink "$p")
36 printf "%s: %s\n" "${p##*/}" "${post##*/}"
37 done
38}
39
40add_list() {
41 local list="$1"
42 mkdir lists/"$list"
43 shift 1
44 echo "$@" >lists/"$list"/title
45}
46
47while getopts_long ":la:" opt \
48 posts required_argument \
49 "" "$@"
50do
51 case $opt in
52 l)
53 print_lists
54 exit 0;;
55 a)
56 shift "$(($OPTLIND - 1))"
57 add_list "$OPTLARG" "$@"
58 exit 0;;
59 posts)
60 print_posts "$OPTLARG"
61 ;;
62 :)
63 printf >&2 '%s: %s\n' "${0##*/}" "$OPTLERR"
64 exit 1;;
65 esac
66done
diff --git a/posts.sh b/posts.sh
deleted file mode 100755
index 464def8..0000000
--- a/posts.sh
+++ /dev/null
@@ -1,41 +0,0 @@
1#!/usr/bin/env bash
2
3shopt -s extglob nullglob
4
5add_to_list() {
6 list=$(basename "$1")
7 file=$(basename "$2")
8 last_link=$(find ./lists/"$list" -regex '.*/[0-9]*$' -printf '%f\n' | sort | tail -n1)
9 new_link=$(printf '%03d\n' $(($last_link + 1)))
10 ln -s ../../posts/"$file" ./lists/"$list"/"$new_link"
11}
12
13new_post() {
14 filename="$1"
15 shift 1
16 cat >posts/$filename <<EOF
17% $@
18EOF
19 add_to_list zz_all "$filename"
20}
21
22
23. ./getopts_long.sh
24
25while getopts_long ":n:a:" opt \
26 "" "$@"
27do
28 case $opt in
29 n)
30 shift "$(($OPTLIND - 1))"
31 new_post "$OPTLARG" "$@"
32 exit 0;;
33 a)
34 shift "$(($OPTLIND - 1))"
35 for f in $@; do add_to_list "$OPTLARG" $f; done
36 exit 0;;
37 :)
38 printf >&2 '%s: %s\n' "${0##*/}" "$OPTLERR"
39 exit 1;;
40 esac
41done
diff --git a/rss/default.rss.do b/rss/default.rss.do
deleted file mode 100644
index a10b032..0000000
--- a/rss/default.rss.do
+++ /dev/null
@@ -1,4 +0,0 @@
1redo-ifchange ../lists/$2.html
2
3find ../lists/$2 -maxdepth 1 -mindepth 1 -not -name 'preview' -not -name 'title' -print0 | \
4 xargs -x -0 -- ../build/generate-rss.hs "$(printf "Dirty-Haskell.org — %s" "$(cat ../lists/$2/title)")"
diff --git a/src/Site.hs b/src/Site.hs
new file mode 100644
index 0000000..d1afbce
--- /dev/null
+++ b/src/Site.hs
@@ -0,0 +1,16 @@
1{-# LANGUAGE OverloadedStrings #-}
2
3import Hakyll
4
5main :: IO ()
6main = hakyllWith config $ do
7 match "/posts/*" $ do
8 route $ setExtension ".html"
9 compile $ do
10 pandocCompiler
11 >>= saveSnapshot "content"
12 >>= loadAndApplyTemplate "templates/default.html" defaultContext
13 >>= relativizeUrls
14
15config :: Configuration
16config = defaultConfiguration
diff --git a/style.css b/style.css
deleted file mode 100644
index 7b89107..0000000
--- a/style.css
+++ /dev/null
@@ -1,40 +0,0 @@
1body {
2 margin: auto;
3 padding-right: 1em;
4 padding-left: 1em;
5 font: normal 1.1em monospace;
6 max-width: 60em;
7 text-align: justify;
8}
9
10.display-math {
11 display: block;
12 margin-top: 0.2em;
13 margin-bottm: 0.2em;
14 text-align: center;
15}
16
17.inline-math {
18 display: inline;
19}
20
21a {
22 color: inherit;
23}
24
25p {
26 margin-bottom: 0
27}
28
29p + p {
30 text-indent: 1.5em;
31 margin-top: 0;
32}
33
34pre {
35 margin-left: 1.5em;
36}
37
38p code {
39 font-style:italic;
40} \ No newline at end of file
diff --git a/sync.do b/sync.do
deleted file mode 100644
index 58a69e0..0000000
--- a/sync.do
+++ /dev/null
@@ -1,2 +0,0 @@
1redo-ifchange htdocs
2rsync -rz -e ssh --delete htdocs/ yggdrasil.li:/var/www/dirty-haskell.org/ \ No newline at end of file
diff --git a/build/template.html5 b/templates/default.html
index 970848f..970848f 100644
--- a/build/template.html5
+++ b/templates/default.html