-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_width.template
81 lines (72 loc) · 1.99 KB
/
get_width.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
%%% Based on the script by Paolo Brasolin:
%%% \url{http://tex.stackexchange.com/a/285774}
%%% See V. Eijkhout, TeX by Topic, A TeXnician's Reference, 5.9.6;
%%% V. Eijkhout, ``Unusual paragraph shapes,'' TUGboat 11: 51--53.
\documentclass{tufte-book}
\usepackage{fontspec}
\usepackage[Latin,Greek,Mathematics,Symbols]{ucharclasses}
% Greek fonts
\newfontfamily\greekfont[ItalicFont={Latin Modern Roman 10 Italic},
ItalicFeatures={FakeSlant=0},
FakeSlant=0.15,
Ligatures=TeX]{Latin Modern Math}
\setTransitionsForGreek{\greekfont}{}
% Math fonts
\newfontfamily\mathsfont[ItalicFont={Latin Modern Roman 10 Italic}, Ligatures=TeX]{Latin Modern Math}
\setTransitionsForSymbols{\mathsfont}{}
\setTransitionsForMathematics{\mathsfont}{}
\newbox\linebox
\newbox\tempbox
\newif\ifoutput
\newdimen\lwMIN
\newdimen\lwMAX
\newdimen\lwINC
\newdimen\lwCUR
\newdimen\lwACT
\newdimen\lwCURMAX
\newdimen\lwALLMIN
\newdimen\hsALLMIN
\newdimen\dwCUR
\newdimen\dwMAX
\newdimen\dwTOL
\def\find#1\par{
\hsize=\lwCUR
\dwMAX=0pt
\lwCURMAX=0pt
\setbox\tempbox\vbox{#1\par\eat}
\ifdim\lwCURMAX<\lwALLMIN\global\lwALLMIN=\lwCURMAX\hsALLMIN=\hsize\fi
\ifdim\lwCUR>\lwMIN
\ifdim\dwMAX<\dwTOL
\advance\lwCUR-\lwINC
\find#1\par\fi\fi
\ifoutput\box\tempbox\fi
}
\def\eat{{
\setbox\linebox\lastbox
\settowidth{\lwACT}{\unhcopy\linebox}
\dwCUR=\dimexpr\lwACT-\dimexpr\lwCUR
\ifdim\dwCUR>\dwMAX\global\dwMAX=\dwCUR\fi
\ifdim\lwACT>\lwCURMAX\global\lwCURMAX=\lwACT\fi
\ifvoid\linebox\else
\unskip\unpenalty\unskip\unpenalty\unskip\unpenalty\unskip\eat
\ifoutput
\noindent\box\linebox\rlap{~\,~\,~\,~\the\dwCUR}
\fi
\fi
}}
\begin{document}
\lwMIN=20pt
\lwMAX=\textwidth
\lwALLMIN=\textwidth
\settowidth{\dwTOL}{alongword}
\lwCUR=\lwMAX
\lwINC=1pt
\outputfalse
\hsize=\lwMAX
\hsALLMIN=\hsize
\hyphenpenalty=100000
\setlength{\parindent}{0pt}
\find $tex_to_measure \par
\showthe\dimexpr\lwALLMIN
\showthe\dimexpr1em
\end{document}