-
Notifications
You must be signed in to change notification settings - Fork 0
/
latex2sixel
executable file
·99 lines (80 loc) · 1.95 KB
/
latex2sixel
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
usage()
{
printf '%s\n' "This is latex2sixel V 1.0.1 :: (TeX Live)
Usage: $0 [OPTION]... TEXSTRING
Options are chosen to be similar to dvips' options where possible:
-D # Output resolution
-O c Image offset
-T c Image size (also accepts '-T bbox' and '-T tight')
-bg s Background color (TeX-style color or 'Transparent')
-fg s Foreground color (TeX-style color)
-h | --help Help
# = number s = string
c = comma-separated dimension pair (e.g., 3.2in,-32.1cm)
TEXSTRING is a LaTeX expression betweeen apostrophes (not quotes).
Examples: '\$\alpha\$' | '\LaTeX' | 'This is math: \$x+y\$'.
Required applications: latex, dvipng, img2sixel.
Terminals supporting sixel graphics: xterm -ti vt340, mintty, mlterm and more."
}
[ $# -eq 0 ] && { usage;exit; };
[ "$1" = -h ] || [ "$1" = --help ] && { usage;exit; };
#
# config (default)
#
pt=11pt
fg=Green
bg=Black
D=150 #120
T=bbox #bbox,tight ...
O=-1.0cm,-2.0cm
img="$(mktemp latex2sixel_XXXXXX)"
jobname="$(mktemp latex2sixel_XXXXXX)"
trap 'rm "$img" "$jobname" "$jobname.aux" "$jobname.dvi" "$jobname.log"' EXIT INT
#
# option parsing
#
while [ $# -gt 1 ]; do
arg="$1"
case $arg in
-D|--resolution)
D="$2"
shift # past argument
;;
-O|--offset)
O="$2"
shift # past argument
;;
-T|--size)
T="$2"
shift # past argument
;;
-fg|--forecolor)
fg="$2"
;;
-bg|--backcolor)
bg="$2"
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
#
# TeX
#
texsrc="$1"
TEX="\documentclass[$pt]{article}
\usepackage{amsmath,amssymb}
\usepackage{breqn}
\pagestyle{empty}
\begin{document}
$texsrc
\end{document}"
TEX="$(printf '%s\n' "$TEX" | tr '\n' ' ')"
LATEX="latex -jobname=$jobname -interaction=nonstopmode"
DVIPNG="dvipng -T $T -D $D -O $O -fg $fg -bg $bg -q -o $img"
printf '%s\n' "$TEX" | $LATEX > /dev/null 2>&1
$DVIPNG "$jobname.dvi" > /dev/null 2>&1
img2sixel "$img"