Commits

Anonymous committed a396a37

Add Sub that recompiles every TexMaths equation

Comments (0)

Files changed (1)

src/TexMathsEquations.bas

 
 End Sub
 
+' This macro recompiles every TexMath equation in Impress documents
+Sub RecompileAllEquations
+	' The Draw component is required
+	If ComponentInstalled( "Draw" ) = FALSE Then
+
+  		msgbox( _("Please install the Draw component to run TexMaths!") )
+  		Exit Sub
 
+	End If	 
+ 
+	' Initialize object to null to allow testing if it was created
+	oDlgMain = null
+	
+	' Set TexMaths configuration
+	SetConfig()
+	
+	' Check program paths
+	CheckProgramPaths()
+	
+	' Exit if configuration was not saved
+	Dim oSystemInfo as Variant
+	oSystemInfo = GetConfigAccess("/ooo.ext.texmaths.Registry/SystemInfo", TRUE)
+	If oSystemInfo.ConfigSaved = "" Then Exit Sub
+	
+	' Get the current document and controller
+ 	Dim oDoc as Variant, oDocCtrl as Variant
+ 	oDoc = ThisComponent
+	oDocCtrl = oDoc.getCurrentController()
+
+	' Test if we are in Writer, Impress or Draw and set the default user preferences
+	Dim sEqSize as String, sEqType as String, sEqLatexCode as String, sEqFormat as String, sEqDPI as String, sEqTransp as String, sEqName as String
+
+	' Default image format, graphic DPI and transparency
+	sEqFormat = glb_sFormat
+	sEqDPI = glb_sGraphicDPI
+	sEqTransp = glb_sTransparency
+
+	If GetDocumentType(oDoc) = "simpress" Then
+
+		' We are in an Impress doc, set default preferences
+		sEqSize = glb_sImpressSize
+		sEqType = glb_sImpressEqType
+		sEqLatexCode = ""
+	Else
+
+		Msgbox GetDocumentType(oDoc) & _(": document type not supported by TexMathsCompileAll")
+		Exit Sub
+
+	End If
+
+	' If there is something selected, then we are in the edit equation mode
+	' and we have to get the equation attributes (font size, equation type, LaTeX code)
+	Dialog = FALSE
+
+	Dim numSlides, numForms, i, j as Integer    
+	Dim oSlide, oShape as Object
+	
+	Dim sDlgArg as String
+	Dim sArray() as String
+	
+
+    numSlides = oDoc.getDrawPages().getCount()
+        
+    ' go through pages
+    For i = 0 to numSlides - 1
+        oSlide = oDoc.drawPages(i)
+        If oSlide.hasElements() Then
+            For j = (oSlide.getCount() - 1) To 0 Step -1
+                oShape = oSlide.getByIndex(j)
+		
+				' For Impress or Draw, check if the selected object is in a SvxShapeCollection
+				If oShape.getImplementationName() <> "SvxShape" and oShape.getImplementationName() <> "SvxShapeText" Then
+					MsgBox oShape.getImplementationName()
+					goto NextShape
+				End If 				
+				sDlgArg = ReadAttributes(oShape)
+				If sDlgArg = "" Then
+					goto NextShape
+	    		End If
+	    		
+	    		
+				sArray()=Split(sDlgArg,"§")
+	
+				' Pre v0.39 equation
+				If Ubound(sArray) = 2 Then
+				
+		    		sEqSize=sArray(0)
+		    		sEqType=sArray(1)
+		    		sEqLatexCode=sArray(2)
+				
+				ElseIf Ubound(sArray) = 5 Then
+	
+		    		sEqSize=sArray(0)
+		    		sEqType=sArray(1)
+		    		sEqLatexCode=sArray(2)
+		    		sEqFormat=sArray(3)
+		    		sEqDPI=sArray(4)
+		    		sEqTransp=sArray(5)
+		    		sEqName=""
+	
+				ElseIf Ubound(sArray) = 6 Then
+	
+		    		sEqSize=sArray(0)
+		    		sEqType=sArray(1)
+		    		sEqLatexCode=sArray(2)
+		    		sEqFormat=sArray(3)
+		    		sEqDPI=sArray(4)
+		    		sEqTransp=sArray(5)
+		    		sEqName=sArray(6)
+				
+				Else
+					goto NextShape
+				End If
+	  		
+	    		oDocCtrl.select(oShape)
+	       		EditEquation = TRUE
+				oShapePosition = oShape.position()
+	    		MakeEquation(sEqSize, sEqType, sEqLatexCode, sEqFormat, sEqDPI, sEqTransp)
+NextShape:
+	
+            Next
+        EndIf
+	Next
+	
+End Sub