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">'
' TexMathsPrefs
'
' Copyright (C) 2012-2020 Roland Baudin (roland65@free.fr)
' Based on the work of Geoffroy Piroux (gpiroux@gmail.com)
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
'
' Macros related to main preferences
' Force variable declaration
Option Explicit
' Set user, temp and package paths
Sub DefaultSysConfig()
' Service to access the user's paths information
Dim aService as Variant, oFileAccess as Variant
aService = CreateUnoService("com.sun.star.util.PathSubstitution")
oFileAccess = createUnoService("com.sun.star.ucb.SimpleFileAccess")
' User path and temp path
glb_UserPath = aService.substituteVariables("$(user)", TRUE) & "/TexMaths/"
glb_TmpPath = aService.substituteVariables("$(user)", TRUE) & "/TexMaths/tmp/"
' Create the user directory if it doesn't exist
If Not oFileAccess.exists(glb_UserPath) Then MkDir(glb_UserPath)
If Not oFileAccess.exists(glb_TmpPath) Then MkDir(glb_TmpPath)
' Get the package path
Const sPrefix = "vnd.sun.star.expand:"
Dim oSystemInfo as Variant
oSystemInfo = GetConfigAccess( "/ooo.ext.texmaths.Registry/SystemInfo", TRUE)
glb_PkgPath = Mid( oSystemInfo.PackageDir , len(sPrefix)+1)
' Get the default context
Dim oContext as Variant, oMacroExpander as Variant
oContext = getProcessServiceManager().DefaultContext
oMacroExpander = oContext.getValueByName("/singletons/com.sun.star.util.theMacroExpander")
glb_PkgPath = oMacroExpander.ExpandMacros(glb_PkgPath)
End Sub
' Set default preferences
Sub DefaultPrefs()
' Latex preferences
glb_WriterSize = "12"
glb_ImpressSize = "28"
glb_DrawSize = "14"
glb_WriterEqType = "display"
glb_ImpressEqType = "display"
glb_DrawEqType = "display"
' Image preferences
glb_Format = "svg"
' Force default to png if the dvisvgm path is empty
Dim oSystemInfo as Variant
oSystemInfo = GetConfigAccess( "/ooo.ext.texmaths.Registry/SystemInfo", TRUE)
If oSystemInfo.DvisvgmPath = "" Then
glb_Format = "png"
End If
glb_GraphicDPI = "600"
glb_WriterTransparency = "FALSE"
glb_ImpressTransparency = "FALSE"
glb_DrawTransparency = "FALSE"
glb_Status = _("Default preferences loaded...")
End Sub
' Return a string with the current preferences
' to be written to the preferences file
Function Preferences() as String
Preferences = _
"GraphicDPI=" & glb_GraphicDPI & chr(10) &_
"FileFormat=" & glb_Format & chr(10) &_
"WriterTransparency=" & glb_WriterTransparency & chr(10) &_
"ImpressTransparency=" & glb_ImpressTransparency & chr(10) &_
"DrawTransparency=" & glb_DrawTransparency & chr(10) &_
"WriterCharSize=" & glb_WriterSize & chr(10) &_
"WriterEquationType=" & glb_WriterEqType & chr(10) &_
"ImpressCharSize=" & glb_ImpressSize & chr(10) &_
"ImpressEquationType=" & glb_ImpressEqType & chr(10) &_
"DrawCharSize=" & glb_DrawSize & chr(10) &_
"DrawEquationType=" & glb_DrawEqType & chr(10)
End Function
' Read the user's preferences file
' Call the routine for data parsing
Sub ReadPrefsFile()
Dim iNumber as Integer
Dim sLine,sPrefs as String
sPrefs = ""
iNumber = Freefile
Open glb_UserPath & "TexMaths.cfg" For Input As iNumber
While Not EOF(iNumber)
Line Input #iNumber, sLine
If sLine <> "" Then sPrefs = sPrefs & chr(10) & sLine
Wend
Close #iNumber
ReadPreferencesFrom( sPrefs )
glb_Status = _("User's preferences loaded...")
End Sub
' 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),"=") Then
sArguments() = Split(sLine(i),"=")
Select Case sArguments(0)
Case "ScriptPath"
Dim sScriptPath as String
sScriptPath = CheckPath(ConvertToURL(sArguments(1)))
Case "GraphicDPI"
glb_GraphicDPI = sArguments(1)
Case "FileFormat"
glb_Format = sArguments(1)
Case "WriterTransparency"
glb_WriterTransparency = sArguments(1)
Case "ImpressTransparency"
glb_ImpressTransparency = sArguments(1)
Case "DrawTransparency"
glb_DrawTransparency = sArguments(1)
Case "WriterCharSize"
glb_WriterSize = sArguments(1)
Case "WriterEquationType"
glb_WriterEqType = sArguments(1)
Case "ImpressCharSize"
glb_ImpressSize = sArguments(1)
Case "ImpressEquationType"
glb_ImpressEqType = sArguments(1)
Case "DrawCharSize"
glb_DrawSize = sArguments(1)
Case "DrawEquationType"
glb_DrawEqType = sArguments(1)
End Select
End If
ii = ii + 1 + Len(sLine(i))
If Len(sPrefs) < ii Then Exit For
Next
End Sub
' Set default preamble
Sub SetDefaultPreamble()
Dim oSystemInfo as Variant
oSystemInfo = GetConfigAccess("/ooo.ext.texmaths.Registry/SystemInfo", TRUE)
' Get compiler
glb_Compiler = oSystemInfo.Compiler
' Default preamble
glb_Preamble = "\usepackage{amsmath}" & chr(10) &_
"\usepackage{amssymb}" & chr(10) &_
"\usepackage[usenames]{color}" & chr(10) &_
"\usepackage{ifxetex}" & chr(10) &_
chr(10) &_
"% XeLaTeX compiler" & chr(10) &_
"\ifxetex" & chr(10) &_
chr(10) &_
" \usepackage{fontspec}" & chr(10) &_
" \usepackage{unicode-math}" & chr(10) &_
chr(10) &_
" % Uncomment these lines for alternative fonts" & chr(10) &_
" %\setmainfont{FreeSerif}" & chr(10) &_
" %\setmathfont{FreeSerif}" & chr(10) &_
chr(10) &_
"% LaTeX compiler" & chr(10) &_
"\else" & chr(10) &_
chr(10) &_
" % Uncomment this line for sans-serif maths font" & chr(10) &_
" %\everymath{\mathsf{\xdef\mysf{\mathgroup\the\mathgroup\relax}}\mysf}" & chr(10) &_
chr(10) &_
"\fi" &_
chr(10)
' Default ignore preamble state
glb_IgnorePreamble = FALSE
End Sub
' Read local preamble - Return 1 if a local preamble was found, else return 0
Function ReadLocalPreamble() as Integer
' Read the local preamble from a UserDefinedProperties property
Dim oDoc as Variant, oProperties as Variant
oDoc = ThisComponent
oProperties = oDoc.DocumentProperties.UserDefinedProperties
' No local stored LaTeX preamble
If Not oProperties.PropertySetInfo.hasPropertyByName("TexMathsPreamble") Then
ReadLocalPreamble = 0
Exit Function
' Read local stored LaTeX preamble
Else
' Decode the local stored preamble string to restore the newline characters (workaround for an LO bug)
glb_Preamble = DecodeNewline( oProperties.getPropertyValue("TexMathsPreamble") )
' Set the ignore preamble state
If oProperties.PropertySetInfo.hasPropertyByName("TexMathsIgnorePreamble") Then
If oProperties.getPropertyValue("TexMathsIgnorePreamble") = "TRUE" Then
glb_IgnorePreamble = TRUE
Else
glb_IgnorePreamble = FALSE
End If
End If
ReadLocalPreamble = 1
End If
End Function
' 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) & "GlobalPreamble.tex"
' Global preamble does not exist, return 0
If Not FileExists(cURL) Then
ReadGlobalPreamble = 0
Exit Function
' Global preamble exists, read it and return 1
Else
' Read and set global preamble
Dim oTextFile as Variant, oFileAccess as Variant, oFileStream as Variant
Dim sText as String, sLine As String
oFileAccess = createUnoService("com.sun.star.ucb.SimpleFileAccess")
oFileStream = oFileAccess.openFileRead(cURL)
oTextFile = createUnoService("com.sun.star.io.TextInputStream")
oTextFile.InputStream = oFileStream
sText = ""
Do While Not oTextFile.IsEOF
sLine = oTextFile.readLine
sText = sText & sLine & chr(10)
Loop
oFileStream.closeInput
oTextFile.closeInput
glb_Preamble = sText
' Read IgnorePreamble variable
Dim oSystemInfo as Variant
oSystemInfo = GetConfigAccess("/ooo.ext.texmaths.Registry/SystemInfo", TRUE)
If oSystemInfo.IgnorePreamble = "TRUE" Then
glb_IgnorePreamble = TRUE
Else
glb_IgnorePreamble = FALSE
End If
ReadGlobalPreamble = 1
End If
End Function
</script:module>
|