-
Notifications
You must be signed in to change notification settings - Fork 10
/
texcaller.i
158 lines (139 loc) · 3.4 KB
/
texcaller.i
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* See doc/index.html for copyright information and documentation. */
/*! \defgroup python Texcaller Python interface
*
* \par Synopsis
*
* \code
import texcaller
texcaller.convert(source, source_format, result_format, max_runs) # returns a pair (result, info)
texcaller.escape_latex(s)
* \endcode
*
* \par Description
*
* These
* <a href="http://www.postgresql.org/">Python</a>
* functions are simple wrappers
* around the \ref c library functions,
* making
* <a href="http://www.tug.org/">TeX</a>
* typesetting
* easily accessible from Python.
*
* \par Example
*
* \include example.py
*
* \par Beware of \c \\u
*
* Unfortunately,
* Python always interprets \c \\uXXXX sequences in unicode strings
* (even in raw unicode strings),
* which interferes badly with common LaTeX commands such as \c \\usepackage{}.
* This means every backslash \c \\ which is followed by the character \c u
* needs to be escaped via \c \\u005c,
* which looks really strange:
*
* \include example_ur_1.py
*
* Fortunately,
* this problem is easily solved by
* using raw byte strings, and
* converting those to unicode strings via the \c decode() method:
*
* \include example_ur_2.py
*/
/*! \cond */
#ifdef SWIGPYTHON
%pythonprepend convert %{
(source, source_format, result_format, max_runs) = args
args = (source.encode('UTF-8'), source_format.encode('UTF-8'), result_format.encode('UTF-8'), max_runs)
%}
%pythonappend convert %{
(result, info) = val
val = (result, info.decode('UTF-8'))
%}
%pythonprepend escape_latex %{
(s,) = args
args = (s.encode('UTF-8'),)
%}
%pythonappend escape_latex %{
val = val.decode('UTF-8')
%}
#endif
/*! \endcond */
/*! \defgroup ruby Texcaller Ruby interface
*
* \par Synopsis
*
* \code
require 'texcaller'
Texcaller.convert(source, source_format, result_format, max_runs) # returns a pair [result, info]
Texcaller.escape_latex(s)
* \endcode
*
* \par Description
*
* These
* <a href="http://www.ruby-lang.org/">Ruby</a>
* functions are simple wrappers
* around the \ref c library functions,
* making
* <a href="http://www.tug.org/">TeX</a>
* typesetting
* easily accessible from Ruby.
*
* \par Example
*
* \include example.rb
*/
/*! \cond */
#ifdef SWIGRUBY
#endif
/*! \endcond */
/*! \defgroup php Texcaller PHP interface
*
* \par Synopsis
*
* \code
texcaller_convert(&$result, &$info, $source, $source_format, $result_format, $max_runs)
texcaller_escape_latex($s)
* \endcode
*
* \par Description
*
* These
* <a href="http://www.php.net/">PHP</a>
* functions are simple wrappers
* around the \ref c library functions,
* making
* <a href="http://www.tug.org/">TeX</a>
* typesetting
* easily accessible from PHP.
*
* \par Example
*
* \include example.php
*/
/*! \cond */
#ifdef SWIGPHP
%rename(texcaller_convert) texcaller::convert;
%rename(texcaller_escape_latex) texcaller::escape_latex;
#endif
/*! \endcond */
/*
* Declarations for all languages
*/
%{
#include "../c/texcaller.h"
%}
%include "typemaps.i"
%include "stl.i"
%module texcaller
namespace texcaller {
void convert(std::string &OUTPUT, std::string &OUTPUT, const std::string &source, const std::string &source_format, const std::string &result_format, int max_runs) throw(std::domain_error, std::runtime_error);
std::string escape_latex(const std::string &s) throw(std::runtime_error);
}
%{
#include "../c/texcaller.c"
%}