File: TexMathsPrefs.xba

package info (click to toggle)
libreoffice-texmaths 0.49-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,388 kB
  • sloc: sh: 67; xml: 32; makefile: 2
file content (323 lines) | stat: -rw-r--r-- 10,491 bytes parent folder | download
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="TexMathsPrefs" script:language="StarBasic">&apos;
&apos;    TexMathsPrefs
&apos;
&apos;	 Copyright (C) 2012-2020 Roland Baudin (roland65@free.fr)
&apos;    Based on the work of Geoffroy Piroux (gpiroux@gmail.com)
&apos;
&apos;    This program is free software; you can redistribute it and/or modify
&apos;    it under the terms of the GNU General Public License as published by
&apos;    the Free Software Foundation; either version 2 of the License, or
&apos;    (at your option) any later version.
&apos;
&apos;    This program is distributed in the hope that it will be useful,
&apos;    but WITHOUT ANY WARRANTY; without even the implied warranty of
&apos;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
&apos;    GNU General Public License for more details.
&apos;
&apos;    You should have received a copy of the GNU General Public License
&apos;    along with this program; if not, write to the Free Software
&apos;    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
&apos;

&apos;    Macros related to main preferences

&apos; Force variable declaration
Option Explicit


&apos; Set user, temp and package paths
Sub DefaultSysConfig()

	&apos; Service to access the user&apos;s paths information
	Dim aService as Variant, oFileAccess as Variant
	aService = CreateUnoService(&quot;com.sun.star.util.PathSubstitution&quot;)
	oFileAccess = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
	
	&apos; User path and temp path
 	glb_UserPath = aService.substituteVariables(&quot;$(user)&quot;, TRUE) &amp; &quot;/TexMaths/&quot;
	glb_TmpPath  = aService.substituteVariables(&quot;$(user)&quot;, TRUE) &amp; &quot;/TexMaths/tmp/&quot;
          
	&apos; Create the user directory if it doesn&apos;t exist
	If Not oFileAccess.exists(glb_UserPath) Then MkDir(glb_UserPath)
	If Not oFileAccess.exists(glb_TmpPath)  Then MkDir(glb_TmpPath)

	&apos; Get the package path
	Const sPrefix = &quot;vnd.sun.star.expand:&quot;
	Dim oSystemInfo as Variant
	oSystemInfo = GetConfigAccess( &quot;/ooo.ext.texmaths.Registry/SystemInfo&quot;, TRUE)
	glb_PkgPath = Mid( oSystemInfo.PackageDir , len(sPrefix)+1)
	
	&apos; Get the default context
	Dim oContext as Variant, oMacroExpander as Variant
	oContext = getProcessServiceManager().DefaultContext
	oMacroExpander = oContext.getValueByName(&quot;/singletons/com.sun.star.util.theMacroExpander&quot;)
	glb_PkgPath = oMacroExpander.ExpandMacros(glb_PkgPath)

End Sub


&apos; Set default preferences
Sub DefaultPrefs()

	&apos; Latex preferences
	glb_WriterSize = &quot;12&quot;
	glb_ImpressSize = &quot;28&quot;
	glb_DrawSize = &quot;14&quot;
	glb_WriterEqType = &quot;display&quot;
	glb_ImpressEqType = &quot;display&quot;
	glb_DrawEqType = &quot;display&quot;

	&apos; Image preferences
	glb_Format = &quot;svg&quot;

	&apos; Force default to png if the dvisvgm path is empty
	Dim oSystemInfo as Variant
	oSystemInfo = GetConfigAccess( &quot;/ooo.ext.texmaths.Registry/SystemInfo&quot;, TRUE)	
	If oSystemInfo.DvisvgmPath = &quot;&quot; Then
		glb_Format = &quot;png&quot;
	End If
	
	glb_GraphicDPI = &quot;600&quot;
	glb_WriterTransparency = &quot;FALSE&quot;
	glb_ImpressTransparency = &quot;FALSE&quot;
	glb_DrawTransparency = &quot;FALSE&quot;
	glb_Status = _(&quot;Default preferences loaded...&quot;)

End Sub


&apos; Return a string with the current preferences
&apos; to be written to the preferences file
Function Preferences() as String

	Preferences = _
	&quot;GraphicDPI=&quot; &amp; glb_GraphicDPI &amp; chr(10) &amp;_
	&quot;FileFormat=&quot; &amp; glb_Format &amp; chr(10) &amp;_
	&quot;WriterTransparency=&quot; &amp; glb_WriterTransparency &amp; chr(10) &amp;_
	&quot;ImpressTransparency=&quot; &amp; glb_ImpressTransparency &amp; chr(10) &amp;_
	&quot;DrawTransparency=&quot; &amp; glb_DrawTransparency &amp; chr(10) &amp;_
	&quot;WriterCharSize=&quot; &amp; glb_WriterSize &amp; chr(10) &amp;_
	&quot;WriterEquationType=&quot; &amp; glb_WriterEqType &amp; chr(10) &amp;_
	&quot;ImpressCharSize=&quot; &amp; glb_ImpressSize &amp; chr(10) &amp;_
	&quot;ImpressEquationType=&quot; &amp; glb_ImpressEqType &amp; chr(10) &amp;_
	&quot;DrawCharSize=&quot; &amp; glb_DrawSize &amp; chr(10) &amp;_
	&quot;DrawEquationType=&quot; &amp; glb_DrawEqType &amp; chr(10)

End Function


&apos; Read the user&apos;s preferences file
&apos; Call the routine for data parsing
Sub ReadPrefsFile()

	Dim iNumber as Integer
	Dim sLine,sPrefs as String
	sPrefs = &quot;&quot;
	iNumber = Freefile
	Open glb_UserPath &amp; &quot;TexMaths.cfg&quot; For Input As iNumber
	While Not EOF(iNumber)

		Line Input #iNumber, sLine
		If sLine &lt;&gt; &quot;&quot; Then sPrefs = sPrefs &amp; chr(10) &amp; sLine 

	Wend
	Close #iNumber
	ReadPreferencesFrom( sPrefs )

	glb_Status = _(&quot;User&apos;s preferences loaded...&quot;)

End Sub



&apos; This fonction parses the preferences from string sPrefs
Sub ReadPreferencesFrom( sPrefs as String )

	Dim i as Integer, ii as Integer
	Dim sLine() as String, sArguments() as String

	If StringNotContains( sPrefs , chr(10)) Then Exit Sub
	sLine() = Split( sPrefs , chr(10))
	ii = 0
	
	For i = 0 to UBound(sLine)

		If Not StringNotContains(sLine(i),&quot;=&quot;) Then 

			sArguments() = Split(sLine(i),&quot;=&quot;)

			Select Case sArguments(0)

				Case &quot;ScriptPath&quot;
					Dim sScriptPath as String
					sScriptPath = CheckPath(ConvertToURL(sArguments(1)))
				Case &quot;GraphicDPI&quot;
					glb_GraphicDPI = sArguments(1)
				Case &quot;FileFormat&quot;
					glb_Format = sArguments(1)
				Case &quot;WriterTransparency&quot;
					glb_WriterTransparency = sArguments(1)
				Case &quot;ImpressTransparency&quot;
					glb_ImpressTransparency = sArguments(1)
				Case &quot;DrawTransparency&quot;
					glb_DrawTransparency = sArguments(1)
				Case &quot;WriterCharSize&quot;
					glb_WriterSize = sArguments(1)
				Case &quot;WriterEquationType&quot;
					glb_WriterEqType = sArguments(1)
				Case &quot;ImpressCharSize&quot;
					glb_ImpressSize = sArguments(1)
				Case &quot;ImpressEquationType&quot;
					glb_ImpressEqType = sArguments(1)
				Case &quot;DrawCharSize&quot;
					glb_DrawSize = sArguments(1)
				Case &quot;DrawEquationType&quot;
					glb_DrawEqType = sArguments(1)

			End Select

		End If

		ii = ii + 1 + Len(sLine(i))
		If Len(sPrefs) &lt; ii  Then Exit For

	Next

End Sub


&apos; Set default preamble
Sub SetDefaultPreamble()

	Dim oSystemInfo as Variant
	oSystemInfo = GetConfigAccess(&quot;/ooo.ext.texmaths.Registry/SystemInfo&quot;, TRUE)
	
	&apos; Get compiler
	glb_Compiler = oSystemInfo.Compiler
	
	&apos; Default preamble
	glb_Preamble = &quot;\usepackage{amsmath}&quot; &amp; chr(10) &amp;_
	&quot;\usepackage{amssymb}&quot; &amp; chr(10) &amp;_
	&quot;\usepackage[usenames]{color}&quot; &amp; chr(10) &amp;_
	&quot;\usepackage{ifxetex}&quot; &amp; chr(10) &amp;_
	chr(10) &amp;_
	&quot;% XeLaTeX compiler&quot; &amp; chr(10) &amp;_
	&quot;\ifxetex&quot; &amp; chr(10) &amp;_
	chr(10) &amp;_
	&quot;    \usepackage{fontspec}&quot; &amp; chr(10) &amp;_
	&quot;    \usepackage{unicode-math}&quot; &amp; chr(10) &amp;_
	chr(10) &amp;_
	&quot;    % Uncomment these lines for alternative fonts&quot; &amp; chr(10) &amp;_
	&quot;    %\setmainfont{FreeSerif}&quot; &amp; chr(10) &amp;_
	&quot;    %\setmathfont{FreeSerif}&quot; &amp; chr(10) &amp;_
	chr(10) &amp;_
	&quot;% LaTeX compiler&quot; &amp; chr(10) &amp;_
	&quot;\else&quot; &amp; chr(10) &amp;_
	chr(10) &amp;_
	&quot;    % Uncomment this line for sans-serif maths font&quot; &amp; chr(10) &amp;_
	&quot;    %\everymath{\mathsf{\xdef\mysf{\mathgroup\the\mathgroup\relax}}\mysf}&quot; &amp; chr(10) &amp;_
	chr(10) &amp;_
	&quot;\fi&quot; &amp;_
	chr(10)
		    		
	&apos; Default ignore preamble state
	glb_IgnorePreamble = FALSE 

End Sub


&apos; Read local preamble - Return 1 if a local preamble was found, else return 0
Function ReadLocalPreamble() as Integer
	
	&apos; Read the local preamble from a UserDefinedProperties property
	Dim oDoc as Variant, oProperties as Variant
	
	oDoc = ThisComponent
	oProperties = oDoc.DocumentProperties.UserDefinedProperties
	
	&apos; No local stored LaTeX preamble
	If Not oProperties.PropertySetInfo.hasPropertyByName(&quot;TexMathsPreamble&quot;) Then
	
		ReadLocalPreamble = 0
		Exit Function
	
	&apos; Read local stored LaTeX preamble
	Else
	
		&apos; Decode the local stored preamble string to restore the newline characters (workaround for an LO bug)
		glb_Preamble = DecodeNewline( oProperties.getPropertyValue(&quot;TexMathsPreamble&quot;) )

		&apos; Set the ignore preamble state
		If oProperties.PropertySetInfo.hasPropertyByName(&quot;TexMathsIgnorePreamble&quot;) Then 		
			
			If oProperties.getPropertyValue(&quot;TexMathsIgnorePreamble&quot;) = &quot;TRUE&quot; Then
				glb_IgnorePreamble = TRUE
			Else
				glb_IgnorePreamble = FALSE
			End If
		
		End If
	
		ReadLocalPreamble = 1
	
	End If

End Function



&apos; Read global preamble - Return 1 if a global preamble was found, else return 0
Function ReadGlobalPreamble() as Integer

	Dim cURL as String
	 
	cURL = ConvertFromURL(glb_UserPath) &amp; &quot;GlobalPreamble.tex&quot;

	&apos; Global preamble does not exist, return 0
	If Not FileExists(cURL) Then

		ReadGlobalPreamble = 0
		Exit Function

	&apos; Global preamble exists, read it and return 1
	Else

		&apos; Read and set global preamble
		Dim oTextFile as Variant, oFileAccess as Variant, oFileStream as Variant
		Dim sText as String, sLine As String
	
		oFileAccess = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
		oFileStream = oFileAccess.openFileRead(cURL)
		oTextFile = createUnoService(&quot;com.sun.star.io.TextInputStream&quot;)
		oTextFile.InputStream = oFileStream
	
		sText = &quot;&quot;
		Do While Not oTextFile.IsEOF
	  		sLine = oTextFile.readLine
			sText = sText &amp; sLine &amp; chr(10)
		Loop
	
		oFileStream.closeInput
		oTextFile.closeInput
	
		glb_Preamble = sText
	
	 	&apos; Read IgnorePreamble variable
		Dim oSystemInfo as Variant
		oSystemInfo = GetConfigAccess(&quot;/ooo.ext.texmaths.Registry/SystemInfo&quot;, TRUE)
		
		If oSystemInfo.IgnorePreamble = &quot;TRUE&quot; Then
			glb_IgnorePreamble = TRUE
		Else
			glb_IgnorePreamble = FALSE
		End If

		ReadGlobalPreamble = 1

	End If
	
End Function
	
</script:module>