-
Notifications
You must be signed in to change notification settings - Fork 0
/
fricas2sixel
executable file
·121 lines (92 loc) · 2.07 KB
/
fricas2sixel
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
function usage()
{
cat <<ENDUSAGE
This is fricas2sixel 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.
ENDUSAGE
}
[[ $# == 0 ]] && { usage;exit; };
[[ $1 == -h ]] && { usage;exit; };
[[ $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=img$RANDOM.png
jobname=job$RANDOM
#
# 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=$BASH_ARGV
TEX=$(cat <<EOF
\documentclass[$pt]{article}
\usepackage{amsmath,amssymb}
\usepackage{breqn}
\pagestyle{empty}
\def\sp{^}\def\sb{_}\def\leqno(#1){}
\def\erf{\mathrm{erf}}\def\sinh{\mathrm{sinh}}
\def\zag#1#2{{{\left.{#1}\right|}\over{\left|{#2}\right.}}}
\def\csch{\mathrm{csch}}
\begin{document}
\begin{math} $texsrc \end{math}
\end{document}
EOF
)
#echo $TEX
LATEX="latex -jobname=$jobname -interaction=nonstopmode"
DVIPNG="dvipng -T $T -D $D -O $O -fg $fg -bg $bg -q -o $img"
echo $TEX | $LATEX > /dev/null 2>&1
$DVIPNG $jobname.dvi > /dev/null 2>&1
img2sixel $img
rm $jobname.*
rm $img