From 29bc89aa55c53950ef22bb5850b8d8c1a0226abd Mon Sep 17 00:00:00 2001 From: Christer van der Meeren Date: Tue, 21 Feb 2017 22:39:31 +0100 Subject: [PATCH] fix #2 --- src/latexdiffcite/latexdiffcite.py | 4 ++-- tests/test_latexdiffcite.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/latexdiffcite/latexdiffcite.py b/src/latexdiffcite/latexdiffcite.py index 99e1f9b..8a72d38 100644 --- a/src/latexdiffcite/latexdiffcite.py +++ b/src/latexdiffcite/latexdiffcite.py @@ -380,7 +380,7 @@ def get_all_ref_keys(oldnew): # find arguments of all LaTeX citation commands in document all_cite_commands = '|'.join(Config.cmd_format.keys()) - args_all_commands = re.findall(r'\\(?:' + all_cite_commands + r')\s*\[?.*?\]?\s*\{(.*?)\}', remove_comments(s), flags=re.S) + args_all_commands = re.findall(r'\\(?:' + all_cite_commands + r')\s*(?:\[[^\]]*?\]\s*){0,2}\{(.*?)\}', remove_comments(s), flags=re.S) # for each citation command, save new references for args in args_all_commands: @@ -656,7 +656,7 @@ def replace_refs_in_tex(oldnew): s = getattr(FileContents, 'tex_' + oldnew) # find all LaTeX citation commands in the string (exclude commented-out commands) - matches = re.findall(r'(\\(cite[tp]?)\s*(\[?.*?\]?)\s*\{(.*?)\})', remove_comments(s), flags=re.S) + matches = re.findall(r'(\\(cite[tp]?)\s*((?:\[[^\]]*?\]\s*){0,2})\{(.*?)\})', remove_comments(s), flags=re.S) # process the references for each citation command for full_cmd, cite_cmd, opt_args, cite_args in matches: diff --git a/tests/test_latexdiffcite.py b/tests/test_latexdiffcite.py index 7feb820..d13f56f 100644 --- a/tests/test_latexdiffcite.py +++ b/tests/test_latexdiffcite.py @@ -66,6 +66,7 @@ def reset_everything(): Postnote only [\textit{Foo}, 2010, and references therein]. Testing spaces [pre \textit{Foo and Bar}, 2011a; \textit{Bar and Baz}, 2013, post]. Testing commented-out stuff % \cite{notused} +Testing command inside args [\odot$\dot{T}$ \textit{Foo}, 2010, \odot$\dot{T}$]. Testing multi-line stuff [\textit{Foo}, 2010; \textit{Foo et al.}, 2011; \textit{Bar and Baz}, 2013] {ACCENTED_CHARACTERS} \bibliography{bibl1, bibl2} @@ -84,6 +85,7 @@ def reset_everything(): Postnote only (\ldiffentity{\textit{Foo} \ldiffentity{2010}}, and references therein). Testing spaces (pre \ldiffentity{\textit{Foo and Bar} \ldiffentity{2011a}}; \ldiffentity{\textit{Bar and Baz} \ldiffentity{2013}}, post). Testing commented-out stuff % \cite{notused} +Testing command inside args (\odot$\dot{T}$ \ldiffentity{\textit{Foo} \ldiffentity{2010}}, \odot$\dot{T}$). Testing multi-line stuff (\ldiffentity{\textit{Foo} \ldiffentity{2010}}; \ldiffentity{\textit{Foo, Bar, and Baz} \ldiffentity{2011}}; \ldiffentity{\textit{Bar and Baz} \ldiffentity{2013}}) {ACCENTED_CHARACTERS} \bibliography{bibl1, bibl2} @@ -101,6 +103,7 @@ def reset_everything(): Postnote only [\textit{Foo}, 2010, and references therein]. Testing spaces [pre \textit{Foo and Bar}, 2011a; \textit{Bar and Baz}, 2013, post]. Testing commented-out stuff % \cite{notused} +Testing command inside args [\odot$\dot{T}$ \textit{Foo}, 2010, \odot$\dot{T}$]. Testing multi-line stuff [\textit{Foo}, 2010; \textit{Foo et~al.}, 2011; \textit{Bar and Baz}, 2013] {ACCENTED_CHARACTERS} \bibliography{bibl1, bibl2} @@ -119,6 +122,7 @@ def reset_everything(): Postnote only (\ldiffentity{\textit{Foo} \ldiffentity{2010}}, and references therein). Testing spaces (pre \ldiffentity{\textit{Foo and Bar} \ldiffentity{2011a}}; \ldiffentity{\textit{Bar and Baz} \ldiffentity{2013}}, post). Testing commented-out stuff % \cite{notused} +Testing command inside args (\odot$\dot{T}$ \ldiffentity{\textit{Foo} \ldiffentity{2010}}, \odot$\dot{T}$). Testing multi-line stuff (\ldiffentity{\textit{Foo} \ldiffentity{2010}}; \ldiffentity{\textit{Foo et~al.} \ldiffentity{2011}}; \ldiffentity{\textit{Bar and Baz} \ldiffentity{2013}}) {ACCENTED_CHARACTERS} \bibliography{bibl1, bibl2} @@ -136,6 +140,7 @@ def reset_everything(): Postnote only [Foo10, and references therein]. Testing spaces [pre Foo11a, Bar13, post]. Testing commented-out stuff % \cite{notused} +Testing command inside args [\odot$\dot{T}$ Foo10, \odot$\dot{T}$]. Testing multi-line stuff [Foo10, Foo11c, Bar13] {ACCENTED_CHARACTERS} \bibliography{bibl1, bibl2} @@ -153,6 +158,7 @@ def reset_everything(): Postnote only [1, and references therein]. Testing spaces [pre 2, 6, post]. Testing commented-out stuff % \cite{notused} +Testing command inside args [\odot$\dot{T}$ 1, \odot$\dot{T}$]. Testing multi-line stuff [1, 5, 6] {ACCENTED_CHARACTERS} \bibliography{bibl1, bibl2}