Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingzefei committed Oct 2, 2024
1 parent 2f4e6fa commit 55e01d9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
2 changes: 1 addition & 1 deletion tests/test_tex2docx.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from tex2docx import LatexToWordConverter
from tex2docx import LatexToWordConverter


class TestLatexToWordConverter(unittest.TestCase):
Expand Down
17 changes: 13 additions & 4 deletions tex2docx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ def convert(
..., help="The path to the output Word document."
),
multifig_dir: str = typer.Option(
None, help="The directory for multi-figure LaTeX files. Defaults to None (use the same directory as input_texfile)."
None,
help="The directory for multi-figure LaTeX files. Defaults to None (use the same directory as input_texfile).",
),
reference_docfile: str = typer.Option(
None, help="The path to the reference Word document. Defaults to None (use the built-in default_temp.docx file)."
None,
help="The path to the reference Word document. Defaults to None (use the built-in default_temp.docx file).",
),
bibfile: str = typer.Option(
None,
help="The path to the BibTeX file. Defaults to None (use the first .bib file found in the same directory as input_texfile).",
),
cslfile: str = typer.Option(
None,
help="The path to the CSL file. Defaults to None (use the built-in ieee.csl file).",
),
bibfile: str = typer.Option(None, help="The path to the BibTeX file. Defaults to None (use the first .bib file found in the same directory as input_texfile)."),
cslfile: str = typer.Option(None, help="The path to the CSL file. Defaults to None (use the built-in ieee.csl file)."),
debug: bool = typer.Option(False, help="Enable debug mode. Defaults to False."),
):
"""Convert LaTeX to Word with the given options."""
Expand All @@ -32,5 +40,6 @@ def convert(
)
converter.convert()


if __name__ == "__main__":
app()
38 changes: 24 additions & 14 deletions tex2docx/tex2docx.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,32 @@ def __init__(
input_texfile.replace(".tex", "_modified.tex")
)
self.output_docxfile = os.path.abspath(output_docxfile)
self.reference_docfile = os.path.abspath(reference_docfile) if reference_docfile else os.path.join(
os.path.dirname(os.path.abspath(__file__)), "default_temp.docx"
self.reference_docfile = (
os.path.abspath(reference_docfile)
if reference_docfile
else os.path.join(
os.path.dirname(os.path.abspath(__file__)), "default_temp.docx"
)
)
if multifig_dir: # if multifig_dir is provided, use it
if multifig_dir: # if multifig_dir is provided, use it
self.multifig_dir = os.path.abspath(multifig_dir)
else: # if multifig_dir is not provided, use the same directory as input_texfile
self.multifig_dir = os.path.join(os.path.dirname(self.input_texfile), "multifigs")

if bibfile: # if bibfile is provided, use it
else: # if multifig_dir is not provided, use the same directory as input_texfile
self.multifig_dir = os.path.join(
os.path.dirname(self.input_texfile), "multifigs"
)

if bibfile: # if bibfile is provided, use it
self.bibfile = os.path.abspath(bibfile)
else: # if bibfile is not provided, search for bibfile in the same directory as input_texfile
bibfile = glob.glob(os.path.join(os.path.dirname(self.input_texfile), "*.bib"))
else: # if bibfile is not provided, search for bibfile in the same directory as input_texfile
bibfile = glob.glob(
os.path.join(os.path.dirname(self.input_texfile), "*.bib")
)
self.bibfile = bibfile[0] if bibfile else None

self.cslfile = os.path.abspath(cslfile) if cslfile else os.path.join(
os.path.dirname(os.path.abspath(__file__)), "ieee.csl"

self.cslfile = (
os.path.abspath(cslfile)
if cslfile
else os.path.join(os.path.dirname(os.path.abspath(__file__)), "ieee.csl")
)
self.luafile = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "resolve_equation_labels.lua"
Expand Down Expand Up @@ -524,7 +534,7 @@ def convert_modified_texfile(self):
)

# Define the command
if self.bibfile is None: # if bibfile is not provided, do not use citation
if self.bibfile is None: # if bibfile is not provided, do not use citation
command = [
"pandoc",
self.output_texfile,
Expand Down Expand Up @@ -600,4 +610,4 @@ def convert(self):
self.create_multifig_texfiles()
self.compile_multifig_texfiles()
self.create_modified_texfile()
self.convert_modified_texfile()
self.convert_modified_texfile()

0 comments on commit 55e01d9

Please sign in to comment.