Skip to content

Commit 8cece69

Browse files
committed
Analyze local packages as part of main document
Fixes #1513
1 parent 86f8055 commit 8cece69

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

latextools/utils/analysis.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,17 +424,14 @@ def _analyze_tex_file(
424424
logger.error("File appears cyclic: %s\n%s", file_name, process_file_stack)
425425
return ana
426426

427-
if not import_path:
428-
base_path, _ = os.path.split(tex_root)
429-
else:
430-
base_path = import_path
427+
base_path = import_path if import_path else os.path.dirname(tex_root)
431428

432429
# store import path at the base path, such that it can be accessed
433430
if import_path:
434431
if file_name in ana._import_base_paths:
435432
if ana._import_base_paths[file_name] != import_path:
436433
logger.warning(
437-
"'%s' is imported twice. " "Cannot handle this correctly in the analysis.",
434+
"'%s' is imported twice. Cannot handle this correctly in the analysis.",
438435
file_name,
439436
)
440437
else:
@@ -472,6 +469,7 @@ def _analyze_tex_file(
472469
# check that we still need to analyze
473470
if only_preamble and ana._state.get("preamble_finished", False):
474471
return ana
472+
475473
elif g("command") in _import_commands and g("args") is not None and g("args2") is not None:
476474
if g("command").startswith("sub"):
477475
next_import_path = os.path.join(base_path, g("args").strip('"'))
@@ -494,6 +492,7 @@ def _analyze_tex_file(
494492
# check that we still need to analyze
495493
if only_preamble and ana._state.get("preamble_finished", False):
496494
return ana
495+
497496
# subfile support:
498497
# if we are not in the root file (i.e. not call from included files)
499498
# and have the command \documentclass[main.tex]{subfiles}
@@ -518,6 +517,22 @@ def _analyze_tex_file(
518517
except KeyError:
519518
pass
520519

520+
# usepackage(local) support:
521+
# analyze existing local packages or stylesheets
522+
elif g("command") == "usepackage" and g("args") is not None:
523+
fn = os.path.join(base_path, os.path.splitext(g("args").strip('"'))[0])
524+
for ext in (".sty", ".tex"):
525+
open_file = fn + ext
526+
if os.path.isfile(open_file):
527+
process_file_stack.append(file_name)
528+
_analyze_tex_file(tex_root, open_file, process_file_stack, ana)
529+
process_file_stack.pop()
530+
break
531+
532+
# check that we still need to analyze
533+
if only_preamble and ana._state.get("preamble_finished", False):
534+
return ana
535+
521536
return ana
522537

523538

0 commit comments

Comments
 (0)