Skip to content

Instantly share code, notes, and snippets.

@sjewo
Last active March 16, 2017 12:09
Show Gist options
  • Save sjewo/bf4f3f314ee75f9d061c532c719cd362 to your computer and use it in GitHub Desktop.
Save sjewo/bf4f3f314ee75f9d061c532c719cd362 to your computer and use it in GitHub Desktop.
Replace Latex2rtf marker with actual images (Linux only, as the path is modified to remove the missing figure folder)
' Replace Latex2rtf marker with actual images in LibreOffice
' Linux only, as the path is modified to remove the missing figure folder
Sub InsertLatex2RtfEps
oText = ThisComponent.Text
RDescrip = ThisComponent.createReplaceDescriptor
RDescrip.searchRegularExpression = True
RDescrip.searchString = "\[###([^\]]*)###\]"
rngs = ThisComponent.findAll(RDescrip)
for i = 0 to rngs.count-1
foundText = rngs.getByIndex(i)
url = foundText.getString()
urllen = Len(url)
Mid(url, urllen-3, 4, "")
Mid(url, 1, 15, "tmp")
FileURL = convertToURL(url)
objTextGraphicObject = ThisComponent.createInstance("com.sun.star.text.TextGraphicObject")
objTextGraphicObject.GraphicURL = FileURL
Curs = oText.createTextCursorByRange(foundText)
oText.insertTextContent(Curs.Start, objTextGraphicObject, false)
next i
RDescrip.replaceString =""
ThisComponent.replaceAll(RDescrip)
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment