-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLaTeX.h
132 lines (112 loc) · 3.66 KB
/
LaTeX.h
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
/*
* This program is licensed under MIT license. For full text of
* the license, see ./LICENSE file.
*/
#include <glib.h>
#define PLUGIN_PREF_ROOT "/plugins/core/latex"
#define PLUGIN_PREF_BGCOLOR PLUGIN_PREF_ROOT "/bgcolor"
#define PLUGIN_PREF_FGCOLOR PLUGIN_PREF_ROOT "/fgcolor"
#define PLUGIN_PREF_FONTSIZE PLUGIN_PREF_ROOT "/fontsize"
#define LATEX_DELIMITER "$$"
#define IMG_FORMAT_STRING "<IMG ID=\"%d\">"
#define LATEX_FORMAT_STRING \
"\\documentclass[preview]{standalone}" \
"\\usepackage{amsmath}" \
"\\usepackage{color}" \
"\\usepackage{amsfonts}" \
"\\usepackage{amssymb}" \
"\\definecolor{bgcolor}{RGB}{%s}" \
"\\definecolor{fgcolor}{RGB}{%s}" \
"\\begin{document}" \
"\\setlength{\\fboxsep}{0.5pt}" \
"\\colorbox{bgcolor}{" \
"\\color{fgcolor}" \
"$%s$" \
"}" \
"\\end{document}"
#define TEX_EXT ".tex"
#define DVI_EXT ".dvi"
#define PNG_EXT ".png"
#define AUX_EXT ".aux"
#define LOG_EXT ".log"
#define DEFAULT_BGCOLOR "255,255,255"
#define DEFAULT_FGCOLOR "0,0,0"
#define DEFAULT_FONTSIZE 9
#define MAX_COMMAND_SIZE 256
#define LATEX_COMMAND_STRING "latex -interaction=batchmode %s"
#define DVIPNG_COMMAND_STRING "dvipng -D %d -o %s %s"
/**
* Returns zero-based position of first occurence of 'text' in 'string'.
* Position of first matched character is returned.
* If string is not found, 'strlen(text)' is returned
* If 'string' or 'text' contains 'NULL', '-1' is returned
*
* string: string to scan
* from: position at which search should begin
* text: text to look for
*/
size_t strstr_index(const char* string, size_t from, const char* text);
/**
* Replaces all occurences of 'what' by 'repl' in 'string'.
* 'string' is reallocated to hold new string.
*/
size_t strrep(char* string, const char* what, const char* repl);
#ifdef _WIN32
/**
* POSIX strndup, duplicates string up to size 'n'.
*/
char * strndup(const char* str, size_t n);
#endif
/**
* Returns number of digits in 'number' considered 10-based representation.
* 'number' is supposed to be non-negative.
*/
int intlen(int number);
/**
* Returns new allocated string which has content of concatenated 'left' and 'right'.
* Caller is responsible for memory deallcation using free.
*/
char* concat(const char* left, const char* right);
/**
* Returns full path to directory of 'file'.
* Caller is responsible for deallocating reult using free.
*/
static char* getdirname(const char const *file);
/**
* Calls 'command' and returns return value of it.
*/
int system_call_command_string(const char* command);
/**
* Returns value from pidgin preference settings.
*/
int get_int_from_pidgin_prefs(const char* pref_string);
/**
* Returns new allocated string representing value from
* pidgin preferences settings. If value is not defined or is
* '""', 'strdup(default_value)' is returned.
*
* Caller is responsible for memory deallocation using free.
*/
const char* get_string_from_pidgin_prefs(const char* pref_string, const char* default_value);
/**
* Converts font size to DPI resolution for dvipng
*/
int font_size_to_resolution(int font_size);
/**
* Creates a png file and registers it to pidgin storage.
* File is created using latex and dvipng calls on text
* 'full_text + from' of length 'len'.
*
* Returns: name of the file or NULL on failure
*/
char* latex_to_png(const char* full_text, size_t from, size_t len);
/**
* Analyzes '*message' from position 'from' scanning for
* LATEX_DELIMITER occurences which are changed to IMG
* tags with image id registered by pidgin after latex_to_png
* call.
*
* Returns: true if message should be viewed
* false if it should be cancelled
*/
static gboolean analyze(char **message, size_t from);