Skip to content

Commit

Permalink
use pexpect to control latex interpreters
Browse files Browse the repository at this point in the history
  • Loading branch information
cvfosammmm committed Jun 28, 2021
1 parent 80e510e commit 70fd3da
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Warning: Building Setzer this way may take a long time (~ 30 minutes on my lapto
This way is probably a bit faster and may save you some disk space. I develop Setzer on Debian and that's what I tested it with. On Debian derivatives (like Ubuntu) it should probably work the same. On distributions other than Debian and Debian derivatives it should work more or less the same. If you want to run Setzer from source on another distribution and don't know how please open an issue here on GitHub. I will then try to provide instructions for your system.

1. Run the following command to install prerequisite Debian packages:<br />
`apt-get install meson python3-gi gir1.2-gtk-3.0 gir1.2-gtksource-4 gir1.2-gspell-1 gir1.2-pango-1.0 gir1.2-poppler-0.18 gir1.2-webkit2-4.0 python3-xdg gettext xdg-utils python3-pdfminer python3-cairo`
`apt-get install meson python3-gi gir1.2-gtk-3.0 gir1.2-gtksource-4 gir1.2-gspell-1 gir1.2-pango-1.0 gir1.2-poppler-0.18 gir1.2-webkit2-4.0 python3-xdg gettext xdg-utils python3-pdfminer python3-cairo python3-pexpect`

2. Download und Unpack Setzer from GitHub

Expand Down
19 changes: 19 additions & 0 deletions org.cvfosammmm.Setzer.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,25 @@
}
]
},
{
"name": "python3-pexpect",
"buildsystem": "simple",
"build-commands": [
"pip3 install --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"pexpect\""
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/e5/9b/ff402e0e930e70467a7178abb7c128709a30dfb22d8777c043e501bc1b10/pexpect-4.8.0.tar.gz",
"sha256": "fc65a43959d153d0114afe13997d439c22823a27cefceb5ff35c2178c6784c0c"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/20/e5/16ff212c1e452235a90aeb09066144d0c5a6a8c0834397e03f5224495c4e/ptyprocess-0.7.0.tar.gz",
"sha256": "5c5d0a3b48ceee0b48485e0c26037c0acd7d29765ca3fbb5cb3831d347423220"
}
]
},
{
"name": "setzer",
"buildsystem": "meson",
Expand Down
30 changes: 18 additions & 12 deletions setzer/document/latex/build_system/builder/builder_build_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

import os
import os.path
import sys
import base64
import shutil
import subprocess
import pexpect
from operator import itemgetter

import setzer.document.latex.build_system.builder.builder_build as builder_build
Expand All @@ -37,32 +38,37 @@ def __init__(self):

def run(self, query):
build_command_defaults = dict()
build_command_defaults['pdflatex'] = 'pdflatex -synctex=1 -interaction=nonstopmode -pdf'
build_command_defaults['xelatex'] = 'xelatex -synctex=1 -interaction=nonstopmode'
build_command_defaults['lualatex'] = 'lualatex --synctex=1 --interaction=nonstopmode'
build_command_defaults['pdflatex'] = 'pdflatex -synctex=1 -interaction=nonstopmode'
build_command_defaults['xelatex'] = 'xelatex -synctex=1 -interaction=errorstopmode'
build_command_defaults['lualatex'] = 'lualatex --synctex=1 --interaction=errorstopmode'
if query.build_data['use_latexmk']:
if query.build_data['latex_interpreter'] == 'pdflatex':
interpreter_option = 'pdf'
else:
interpreter_option = query.build_data['latex_interpreter']
build_command = 'latexmk -' + interpreter_option + ' -synctex=1 -interaction=nonstopmode' + query.build_data['additional_arguments']
build_command = 'latexmk -' + interpreter_option + ' -synctex=1 -interaction=errorstopmode' + query.build_data['additional_arguments']
else:
build_command = build_command_defaults[query.build_data['latex_interpreter']] + query.build_data['additional_arguments']

arguments = build_command.split()
arguments.append('-output-directory=' + os.path.dirname(query.tex_filename))
arguments.append(query.tex_filename)
try:
self.process = subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=os.path.dirname(query.tex_filename))
self.process = pexpect.spawn(build_command + ' -output-directory="' + os.path.dirname(query.tex_filename) + '" "' + query.tex_filename + '"', cwd=os.path.dirname(query.tex_filename))
except FileNotFoundError:
self.cleanup_files(query)
self.throw_build_error(query, 'interpreter_missing', arguments[0])
return
self.process.communicate()
try:
self.process.wait()
except AttributeError:
pass

while True:
try:
out = self.process.expect(['\r\n', pexpect.EOF, pexpect.TIMEOUT], timeout=1)
except AttributeError:
break
if out == 0:
pass
else:
break

# parse results
try:
Expand Down Expand Up @@ -92,7 +98,7 @@ def run(self, query):

def stop_running(self):
if self.process != None:
self.process.kill()
self.process.terminate(True)
self.process = None

def parse_build_log(self, query):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self):
r'(?:Overfull \\hbox|Underfull \\hbox|' +
r'No file .*\.|File .* does not exist\.|' +
r'(?:LaTeX|pdfTeX|LuaTeX|Package|Class) .*Warning.*:|LaTeX Font Warning:|' +
r'!(?:LaTeX|pdfTeX|LuaTeX|Package|Class) error|' +
r'!(?: )(?:LaTeX|pdfTeX|LuaTeX|Package|Class) error|' +
r'! ).*\n)')
self.badbox_line_number_regex = ServiceLocator.get_regex_object(r'lines ([0-9]+)--([0-9]+)')
self.other_line_number_regex = ServiceLocator.get_regex_object(r'(l\.| input line \n| input line )([0-9]+)( |\.)')
Expand Down

0 comments on commit 70fd3da

Please sign in to comment.