Skip to content

Commit

Permalink
fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
cmeeren committed Feb 21, 2017
1 parent 4d6ef1b commit 29bc89a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/latexdiffcite/latexdiffcite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_latexdiffcite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}
Expand All @@ -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}
Expand All @@ -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}
Expand All @@ -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}
Expand All @@ -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}
Expand Down

0 comments on commit 29bc89a

Please sign in to comment.