Sublime text build system - how to auto open pdfs - latex

I followed instructions provided here(How to create a shortcut for user's build system in Sublime Text?) to compile latex documents in xelatex, and on top of that I would also like it to automatically open pdf after compiling just like with latexmk, how can I achieve that? The document is built just fine, but I have to open it each time manually.

Here's an extension to the CompileWithXelatexCommand implementation that successfully opens the PDF in my default PDF viewer.
import sublime, sublime_plugin
import os
import time
class CompileWithXelatexCommand(sublime_plugin.TextCommand):
def run(self, edit):
if '/usr/texbin' not in os.environ['PATH']:
os.environ['PATH'] += ':/usr/texbin'
base_fname = self.view.file_name()[:-4]
pdf_fname = base_fname + ".pdf"
self.view.window().run_command('exec',{'cmd': ['xelatex','-synctex=1','-interaction=nonstopmode',base_fname]})
tries = 5
seconds_to_wait = 1
while tries > 0:
if os.path.isfile(pdf_fname):
break
time.sleep(seconds_to_wait)
seconds_to_wait *= 2
tries -= 1
os.system("open " + pdf_fname)
The polling loop is required; otherwise, the open call may happen before the PDF has been generated. There may be a cleaner way to synchronously exec a sequence of commands via run_command.
I don't have access to Windows now, but from this post you'll probably just need to change "open " to "start ". The PATH initialization logic will either need to be eliminated or adjusted.

Related

How to get a linefeed when writing files with ActionScript with Adobe Indesign Scripting

I'm writing some scripts in ActionScript to automate some tasks in Adobe Indesign 2019 (part of the Creative Cloud Suite), but this applies to all scripting for all applications in Adobe Creative Cloud.
I don't want to use ExtendScript Toolkit for editing/running the script, because it is terribly slow.
Because there is no such thing as console.log() available (at least that I'm aware of) and alert() will stop for user input to continue, I created a small file logger, but it does not append the file, but keeps on overwriting the first line. I use tail -f indesign.log to monitor the log file.
Here is the code of the logger
function logger(message){
var logFilePath = new File ('indesign.log');
logFilePath.encoding = 'UTF-8';
try {
logFilePath.open('a');
}
catch(err) {
logFilePath.close();
logFilePath.open('a');
}
logFilePath.write(new Date().toLocaleString() +": " + message + "\n");
//logFilePath.writeln(new Date().toLocaleString() +": " + message + "\n");
logFilePath.close()
}
logger("Script started")
logger("2nd line")
logger("3rd line")
logger("4th line")
logger("Script finished")
I tried also using writeln instead of write, but it does not make a difference.
I tried different line feeds, like "\n" and "\r\n", but it does not make a difference.
I tried different File.open options like .open('w'), .open('ra'). The documentation about this is either not clear or really outdated (Or I just can't find it).
Any suggestions in the comments about the best IDE to edit/run ActionScripts is highly appreciated.

Programmatically open a UserForm from an external script / program / host application

Given that I have a UserForm embedded in one of the following:
an Excel workbook named c:\myBook.xslm
a Word document c:\myDocument.docm, or
a PowerPoint presentation named c:\myPresentation.ppm
What Automation properties / methods do I need to use in order to open and display the UserForm from an external script / host application / program?
For example, let's say I have the following JScript running under WSH:
var app = new ActiveXObject('Excel.Application');
app.Visible = true;
var book = app.Workbooks.Open('c:\myBook.xlsm');
// open UserForm here
How would I proceed to open the UserForm?
Note: I am looking for a solution that would work with an arbitrary document. This precludes manually (but not programmatically as part of the script) adding a Sub to show the UserForm, which can be called from the external script.
An idea is to override the document open mehtods. At least for Microsoft Word and Excel:
' Word
Private Sub Document_Open()
UserForm1.Show
End Sub
' Excel
Private Sub Workbook_Open()
UserForm1.Show
End Sub
At word and excel document open, the dialog will be shown.
For Powerpoint its a bit more complicated:
How to auto execute a macro when opening a Powerpoint presentation?
Update
After additional information in the question this is not a solution anymore. A starting point how to create code an add it to a VBA project can be found here: https://stackoverflow.com/a/34838194/1306012
Also this website provides additional information: http://www.cpearson.com/excel/vbe.aspx

Hyperlinks without file://... with openpyxl to open a ws from the same wb?

I want open ws2 inside the same libreoffice wb with a hyperlink in a cell on ws1.
My code is:
wb["test"].cell(row = 1, column = 2).hyperlink = '#%s' % "test2"
This works, but openpyxl adds file://... to the link and a new instance of libreoffice starts (and auto close) with every click on my hyperlink.
If i add manually a hyperlink to libreoffice calc no file:// is added and no other instances of libreoffice starts.
What target_modes are supported?
I believe target_mode = "External is hard coded inside the openpyxl cell hyperlink attr. wb.cell()._hyperlink_rel.target_mode = "External
It's fair to say that support for hyperlinks isn't perfect. However, starting with version 2.3 there is at least full support for the type. The relevant code for serialising could easily be adapted to reflect this.

open office crashes after some time giving garbled font in converted PDF

We are converting word to pdf using the openoffice(3.4.1 version) in java with JODConverter.
below is the code used.
OpenOfficeConnection connection =
new SocketOpenOfficeConnection(2100);
try
{
connection.connect();
DocumentConverter converter =
new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
connection.disconnect();
return "Sucess " + DestinationPath + DestinationFileName;
}
catch (Exception localException1) {
}
The problem is that after random no of days the converted PDF contains the garbled fonts.
like # # ! $ $ " % &
The only solution we have so far is to restart the server. System guys are saying the the problem is with Open Office.
We are using open office to convert the document since it converts the doc files exactly including all the formatting and table structure.
what could be the solution to this.
So OpenOffice can be a little temperamental when running on a server, especially as it isn't multi-threaded and you end up having to run a pool of OpenOffice processes - see How can I use OpenOffice in server mode as a multithreaded service?.
Added to that often the rendering is off when converting to PDF - see https://forum.openoffice.org/en/forum/viewtopic.php?f=7&t=68865 which is why you may want to consider using a conversion service to automate the conversion tasks for you ?
For complete transparency I work for Zamzar (an online file conversion service), we have recently released a developer API - https://developers.zamzar.com/ that allows you to convert between a multitude of file types, specifically applicable to you here in that we support both doc and docx to pdf with little or not loss in the way the PDF is rendered. It maybe worth a look to see if this is a better alternative to trying to run your own solution through OpenOffice on a server.

saving data with TextEdit

I want to use TextEdit to save data. what I have so far
tell application "TextEdit"
open /Users/UserName/Desktop/save.rtf
end tell
This gives me
"Expected “given”, “in”, “of”, expression, “with”, “without”, other parameter name, etc. but found unknown token."
and highlights the . in .rtf I tried removing the .rtf
but when I compile it it turns into
(open) / Users / username / desktop / (save)
This code gives "The variable Users is not defined."
also if possible can I have TextEdit run in the background without opening a window?
Put quotes around the path and use POSIX file to get a file object for the path:
tell application "TextEdit"
open POSIX file "/Users/UserName/Desktop/save.rtf"
end tell
You can modify the text of a document by changing the text property:
tell application "TextEdit"
set text of document 1 to text of document 1 & "aa"
end tell
It removes all styles in rich text documents. It also inserts the text as 12-point Helvetica in plain text documents, regardless of the default font.
Creating a new rtf file:
tell application "TextEdit"
make new document at beginning with properties {text:"aa"}
close document 1 saving in POSIX file "/tmp/a.rtf"
end tell
printf %s\\n aa | textutil -inputencoding UTF-8 -convert rtf -stdin -output a.rtf

Resources