forked from avrdudes/avr-libc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath2dox.in
More file actions
91 lines (73 loc) · 2.16 KB
/
Copy pathmath2dox.in
File metadata and controls
91 lines (73 loc) · 2.16 KB
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
#!@PYTHON@
# -*- mode: python -*-
# @configure_input@
# Used by doc/api/Makefile[.am] since Doxygen messes up
# formulae in man pages.
from __future__ import print_function
import sys, re
# For each {{{ formula }}} line we generate 3 versions:
# \htmlonly, \latexonly and \manonly.
pat_math = re.compile(r"\s*{{{(.*)}}}(.*)")
repl_html = (("+/-", "±"),
("-", "−"),
("*", "·"))
repl_tex = (("*", r"\cdot "),
("≈", r"\approx "),
("·", r"\cdot "),
("°", r"^\circ "),
("π", r"\pi "),
("+/-", r"\pm "),
("log", r"\log "),
("<i>", r"\mathit{"),
("</i>", "}"),
("<sup>", "^{"),
("</sup>", "}"),
("<sub>", "_{"),
("</sub>", "}"),
(" ", " "))
repl_man = (("≈", "="),
("·", " * "),
("°", " degree"),
(" ", " "),
("π", " pi "),
("<i>", ""),
("</i>", ""),
("<sup>", "^{"),
("</sup>", "}"),
("<sub>", "_{"),
("</sub>", "}"),
("pi /", "pi/"),
("{x}", "x"),
("{2}", "2"),
(" ", " "))
def out (str):
print (str)
for line in sys.stdin.readlines():
m = pat_math.match (line.strip())
if not m:
print (line, end="")
continue
math = m.group(1)
ende = m.group(2)
m_html = math
for (old,new) in repl_html:
m_html = m_html.replace (old, new)
m_tex = math
for (old,new) in repl_tex:
m_tex = m_tex.replace (old, new)
m_man = math
for (old,new) in repl_man:
m_man = m_man.replace (old, new)
out (r"\htmlonly");
out (m_html + ende);
out (r"\endhtmlonly");
out (r"\latexonly");
out (r"\begin{math} " + m_tex + r"\end{math} " + ende);
out (r"\endlatexonly");
out (r"\manonly");
out (".EQ");
out (m_man)
out (".EN");
if ende:
out (ende);
out (r"\endmanonly");