How Can I Render Xetex Using Swift
I am working on a Cocoa application using Swift 4.0 and I am trying to render LaTeX using a xetex compiler. The main draw of my application is that it's supposed to be able to render using different .ttf's so that's why I believe I need xetex (or even luaLaTeX).
Here's what I tried
I considered using a cloud-based LaTeX renderer so I wouldn't have to worry about installing Xetex for each system but this didn't pan out very well because I could only find a paid service that does this in Node.js which I don't think I can use.
Next, I assumed that the user had followed an instruction to download xetex online and I used a system call via Process() using the /Library/TeX/texbin/xetex command and this almost worked but Xcode grumbled about security giving me the message
compileLatex.sh: line 3: /Library/TeX/texbin/xetex: Operation not permitted
Are there any known workarounds for this that I can do? If I could somehow bundle in a xetex compiler with my application, I think that would be good but I have no idea how to do something like that.
Relevent Code
Contents of compileLatex.sh which is called by the Process()
#!/bin/bash
/Library/TeX/texbin/xetex "$1"
open "$2"
Contents of the ViewController that calls the bash script.
let file = "TemplateMODIFIED.tex"
if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
var env = ProcessInfo.processInfo.environment
var path = env["PATH"] as! String
path = "/Library/TeX/texbin:" + path
env["PATH"] = path
let task = Process()
task.launchPath = "/bin/bash"
task.environment = env
task.arguments = [dir.path + "/compileLatex.sh", dir.path + "/TemplateMODIFIED.tex", dir.path + "/TemplateMODIFIED.pdf"]
task.launch()
}
Any advice on either a workaround or best practice I should use is appreciated. Thank you!
UPDATE: I just learned about the project.entitlements file for the Cocoa project so by switching Sandbox mode to off I was able to perform the system call and overcome the Operation not permitted
error. So I'm able to get it to work, but I'm still not fully satisfied with this solution since the user must download and install xetex before using this application.
上一篇: fontspec(xetex / luatex)和fontconfig
下一篇: 如何使用Swift渲染Xetex