Skip to content

Commit bbc7003

Browse files
author
Austin Clements
committed
Make undefined references messages more user-friendly
1 parent 19383a2 commit bbc7003

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

latexrun

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,13 +875,32 @@ class LaTeX(Task):
875875

876876
# Parse the log
877877
logfile = open(extra['jobname'] + '.log', 'rt', errors='surrogateescape')
878-
for msg in LaTeXFilter(self.__nowarns).feed(
879-
logfile.read(), True).get_messages():
878+
for msg in self.__clean_messages(
879+
LaTeXFilter(self.__nowarns).feed(
880+
logfile.read(), True).get_messages()):
880881
print(msg, file=sys.stderr)
881882

882883
# Return LaTeX's exit status
883884
return extra['status']
884885

886+
def __clean_messages(self, msgs):
887+
"""Make some standard log messages more user-friendly."""
888+
have_undefined_reference = False
889+
for msg in msgs:
890+
if msg.msg.startswith('[LaTeX] '):
891+
# Strip unnecessary package name
892+
msg = msg._replace(msg=msg.msg.split(' ', 1)[1])
893+
if re.match(r'Reference .* undefined', msg.msg):
894+
have_undefined_reference = True
895+
if have_undefined_reference and \
896+
re.match(r'There were undefined references', msg.msg):
897+
# LaTeX prints this at the end so the user knows it's
898+
# worthwhile looking back at the log. Since latexrun
899+
# makes the earlier messages obvious, this is
900+
# redundant.
901+
continue
902+
yield msg
903+
885904
def get_tex_filename(self):
886905
return self.__tex_filename
887906

test/T-missing-input.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
%% status: 1
88

99
%% output:
10-
%% T-missing-input.tex:4: error: [LaTeX] File `does-not-exist.tex' not found
10+
%% T-missing-input.tex:4: error: File `does-not-exist.tex' not found
1111
%% at <read *>
1212
%% from \input{does-not-exist}
1313
%% T-missing-input.tex: error: ==> Fatal error occurred, no output PDF file produced!

test/T-new-input.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ rm -rf $TMP
2828

2929
## output:
3030
## chap1 does not exist
31-
## tmp.T-new-input/test.tex:4: error: [LaTeX] File `./tmp.T-new-input/chap1.tex' not found
31+
## tmp.T-new-input/test.tex:4: error: File `./tmp.T-new-input/chap1.tex' not found
3232
## at <read *>
3333
## from \input{./tmp.T-new-input/chap1}
3434
## tmp.T-new-input/test.tex: error: ==> Fatal error occurred, no output PDF file produced!

0 commit comments

Comments
 (0)