Add biblatex support

This commit is contained in:
Augusto Gunsch 2022-02-17 12:13:05 -03:00
parent 22765e7601
commit 0f222e567a
1 changed files with 28 additions and 5 deletions

View File

@ -109,6 +109,9 @@ class TeXFile:
m = findall(r'\\documentclass\{(.*)\}', self.raw_content) m = findall(r'\\documentclass\{(.*)\}', self.raw_content)
self.document_class = m[0] if m else 'article' self.document_class = m[0] if m else 'article'
m = findall(r'\\usepackage(\[.*\])?\{biblatex\}', self.raw_content)
self.biblatex = bool(m)
def expand_macros(self): def expand_macros(self):
content = self.raw_content content = self.raw_content
breadcrumbs = str(self.pretty_breadcrumbs).replace('>', breadcrumbs = str(self.pretty_breadcrumbs).replace('>',
@ -211,14 +214,11 @@ class PdfFile(FromTeX):
def __init__(self, tex_file): def __init__(self, tex_file):
super().__init__(tex_file, '.pdf') super().__init__(tex_file, '.pdf')
def write_output(self): def run_pdflatex(self):
parent_dir = self.output_file.parent
makedirs(parent_dir, exist_ok=True)
args = [ args = [
'pdflatex', 'pdflatex',
'-jobname', self.output_file.stem, '-jobname', self.output_file.stem,
'-output-directory', parent_dir, '-output-directory', self.output_file.parent,
'-shell-escape' '-shell-escape'
] ]
@ -237,6 +237,29 @@ class PdfFile(FromTeX):
print(proc.stderr, file=stderr) print(proc.stderr, file=stderr)
exit(proc.returncode) exit(proc.returncode)
def run_biber(self):
args = [
'biber',
self.output_file.with_suffix('')
]
proc = run(args,
capture_output=True)
if proc.returncode != 0:
print(proc.stdout, file=stderr)
print(proc.stderr, file=stderr)
exit(proc.returncode)
def write_output(self):
makedirs(self.output_file.parent, exist_ok=True)
self.run_pdflatex()
if self.tex_file.biblatex:
self.run_biber()
self.run_pdflatex()
def write_files(): def write_files():
changed = False changed = False