Created
October 17, 2018 23:40
-
-
Save scanzy/7dfaeb949aa3fdcf07e3729de0df5269 to your computer and use it in GitHub Desktop.
Simple LibreOffice Macro (VB) to render correctly latex content in .docx files exported from Dropbox Paper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'This script calls functions from the LibreOffice TexMaths extension | |
'Make sure TexMaths is installed, along with Tex | |
Sub PaperLatex | |
dim t as string | |
dim oDoc as object | |
dim oSearch as object | |
dim oResult as object | |
dim oCursor as object | |
'gets services | |
oDoc = thiscomponent | |
oCursor = oDoc.CurrentController.ViewCursor | |
oSearch = oDoc.createSearchDescriptor() | |
'search setup | |
with oSearch | |
.SearchString = "$$" | |
.SearchRegularExpression = false | |
.SearchCaseSensitive = true | |
end with | |
SetConfig() 'configures latex converter extension | |
'starts searching | |
oResult = oDoc.findFirst(oSearch) | |
Do While not isNull(oResult) | |
'selects first $$ | |
oCursor.CollapseToStart() | |
oCursor.gotoRange(oResult, false) | |
Do 'expands selection to $$...$$ | |
oCursor.goRight(1, true) | |
Loop Until Right(oCursor.string, 2) = "$$" | |
'gets text inside $$...$$ | |
t = Mid(oCursor.string, 3,Len(oCursor.string) - 4) | |
'checks text too long | |
If Len(t) > 200 Then | |
'asks if contiue or not | |
If MsgBox(t,1) = 2 Then Exit Do | |
End If | |
'converts to latex | |
If MakeEquation(12, "inline", t, "svg", 600, FALSE, "") = -1 Then Exit Do | |
Wait 100 'this is needed, I don't know why... | |
'finds next $$ | |
oResult = oDoc.findNext(oResult.End, oSearch) | |
Loop | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment