From: <st...@us...> - 2007-04-24 20:23:16
|
Author: strank Date: 2007-04-24 22:22:57 +0200 (Tue, 24 Apr 2007) New Revision: 5050 Modified: branches/adjacent-citations/docs/dev/rst/alternatives.txt branches/adjacent-citations/docs/user/latex.txt branches/adjacent-citations/docutils/parsers/rst/states.py branches/adjacent-citations/docutils/writers/latex2e/__init__.py branches/adjacent-citations/test/test_parsers/test_rst/test_inline_markup.py branches/adjacent-citations/test/test_writers/test_latex2e.py Log: Removed the rst-syntax change, implemented citation groups only in the latex writer. Modified: branches/adjacent-citations/docs/dev/rst/alternatives.txt =================================================================== --- branches/adjacent-citations/docs/dev/rst/alternatives.txt 2007-04-18 14:02:16 UTC (rev 5049) +++ branches/adjacent-citations/docs/dev/rst/alternatives.txt 2007-04-24 20:22:57 UTC (rev 5050) @@ -1832,6 +1832,21 @@ Disadvantages: a bit ugly. +Adjacent citation references +============================ + +A special case for inline markup was proposed and implemented: +multiple citation references could be joined into one:: + + [cite1]_[cite2]_ instead of requiring [cite1]_ [cite2]_ + +However, this was rejected as an unwarranted exception to the rules +for inline markup. +(The main motivation for the proposal, grouping citations in the latex writer, +was implemented by recognising the second group in the example above and +transforming it into ``\cite{cite1,cite2}``.) + + ----------------- Not Implemented ----------------- Modified: branches/adjacent-citations/docs/user/latex.txt =================================================================== --- branches/adjacent-citations/docs/user/latex.txt 2007-04-18 14:02:16 UTC (rev 5049) +++ branches/adjacent-citations/docs/user/latex.txt 2007-04-24 20:22:57 UTC (rev 5050) @@ -364,6 +364,10 @@ If ``use-latex-citations`` is used a bibliography is inserted right at the end of the document. *This should be customizable*. +If ``use-latex-citations`` is used adjacent citation references (separated +only by a single space or a newline) are combined to a single citation +group, i.e. ``[cite1]_ [cite2]_`` results in ``\cite{cite1,cite2}``. + Tables ------ Modified: branches/adjacent-citations/docutils/parsers/rst/states.py =================================================================== --- branches/adjacent-citations/docutils/parsers/rst/states.py 2007-04-18 14:02:16 UTC (rev 5049) +++ branches/adjacent-citations/docutils/parsers/rst/states.py 2007-04-24 20:22:57 UTC (rev 5050) @@ -514,13 +514,6 @@ non_whitespace_after = r'(?![ \n])' # Alphanumerics with isolated internal [-._] chars (i.e. not 2 together): simplename = r'(?:(?!_)\w)+(?:[-._](?:(?!_)\w)+)*' - # Special case for adjacent citation references: - citref_concatenator = ']_[' - citation_labels = (r'%s(?:%s%s)*' - % (simplename, - re.escape(citref_concatenator), - simplename) - ) # Valid URI characters (see RFC 2396 & RFC 2732); # final \x00 allows backslash escapes in URIs: uric = r"""[-_.!~*'()[\];/:@&=+$,%a-zA-Z0-9\x00]""" @@ -553,8 +546,7 @@ [r'[0-9]+', # manually numbered r'\#(%s)?' % simplename, # auto-numbered (w/ label?) r'\*', # auto-symbol - r'(?P<citationlabels>%s)' % citation_labels, # citation ref - ] + r'(?P<citationlabel>%s)' % simplename] # citation reference ) ] ), @@ -864,16 +856,11 @@ string = match.string before = string[:match.start('whole')] remaining = string[match.end('whole'):] - refnodes = [] - if match.group('citationlabels'): - labels = label.split(Inliner.citref_concatenator) - refnames = refname.split(Inliner.citref_concatenator) - for label, refname in zip(labels, refnames): - refnode = nodes.citation_reference('[%s]_' % label, - refname=refname) - refnode += nodes.Text(label) - self.document.note_citation_ref(refnode) - refnodes.append(refnode) + if match.group('citationlabel'): + refnode = nodes.citation_reference('[%s]_' % label, + refname=refname) + refnode += nodes.Text(label) + self.document.note_citation_ref(refnode) else: refnode = nodes.footnote_reference('[%s]_' % label) if refname[0] == '#': @@ -892,8 +879,7 @@ self.document.note_footnote_ref(refnode) if utils.get_trim_footnote_ref_space(self.document.settings): before = before.rstrip() - refnodes.append(refnode) - return (before, refnodes, remaining, []) + return (before, [refnode], remaining, []) def reference(self, match, lineno, anonymous=None): referencename = match.group('refname') Modified: branches/adjacent-citations/docutils/writers/latex2e/__init__.py =================================================================== --- branches/adjacent-citations/docutils/writers/latex2e/__init__.py 2007-04-18 14:02:16 UTC (rev 5049) +++ branches/adjacent-citations/docutils/writers/latex2e/__init__.py 2007-04-24 20:22:57 UTC (rev 5050) @@ -1078,8 +1078,17 @@ def depart_citation_reference(self, node): if self._use_latex_citations: + followup_citation = False + # check for a following citation separated by a space or newline next_sibling = node.next_node(descend=0, siblings=1) - if next_sibling.__class__ == node.__class__: + if (isinstance(next_sibling, nodes.Text) + and next_sibling.astext() in (' ', '\n')): + nenext_sibling = next_sibling.next_node(descend=0, siblings=1) + if nenext_sibling.__class__ == node.__class__: + followup_citation = True + # remove the space/newline: + next_sibling.data = '' + if followup_citation: self.body.append(',') else: self.body.append('}') Modified: branches/adjacent-citations/test/test_parsers/test_rst/test_inline_markup.py =================================================================== --- branches/adjacent-citations/test/test_parsers/test_rst/test_inline_markup.py 2007-04-18 14:02:16 UTC (rev 5049) +++ branches/adjacent-citations/test/test_parsers/test_rst/test_inline_markup.py 2007-04-24 20:22:57 UTC (rev 5050) @@ -638,12 +638,12 @@ <footnote_reference auto="*" ids="id1"> """], ["""\ -No footnote refs: [*]_[#label]_ [#]_[2]_ [1]_[*]_ +Adjacent footnote refs are not possible: [*]_[#label]_ [#]_[2]_ [1]_[*]_ """, """\ <document source="test data"> <paragraph> - No footnote refs: [*]_[#label]_ [#]_[2]_ [1]_[*]_ + Adjacent footnote refs are not possible: [*]_[#label]_ [#]_[2]_ [1]_[*]_ """], ] @@ -677,19 +677,12 @@ but not [CIT 1]_ """], ["""\ -Adjacent citations: -[citation]_[cit-ation]_[CIT1]_ +Adjacent citation refs are not possible: [citation]_[CIT1]_ """, """\ <document source="test data"> <paragraph> - Adjacent citations: - <citation_reference ids="id1" refname="citation"> - citation - <citation_reference ids="id2" refname="cit-ation"> - cit-ation - <citation_reference ids="id3" refname="cit1"> - CIT1 + Adjacent citation refs are not possible: [citation]_[CIT1]_ """], ] Modified: branches/adjacent-citations/test/test_writers/test_latex2e.py =================================================================== --- branches/adjacent-citations/test/test_writers/test_latex2e.py 2007-04-18 14:02:16 UTC (rev 5049) +++ branches/adjacent-citations/test/test_writers/test_latex2e.py 2007-04-24 20:22:57 UTC (rev 5050) @@ -233,8 +233,15 @@ totest_latex_citations['adjacent_citations'] = [ # input ["""\ -Two citations: [MeYou2007]_[YouMe2007]_. +Two non-citations: [MeYou2007]_[YouMe2007]_. +Need to be separated for grouping: [MeYou2007]_ [YouMe2007]_. + +Two spaces (or anything else) for no grouping: [MeYou2007]_ [YouMe2007]_. + +But a line break should work: [MeYou2007]_ +[YouMe2007]_. + .. [MeYou2007] not. .. [YouMe2007] important. """, @@ -248,8 +255,14 @@ \\setlength{\\locallinewidth}{\\linewidth} -Two citations: \\cite{MeYou2007,YouMe2007}. +Two non-citations: {[}MeYou2007{]}{\_}{[}YouMe2007{]}{\_}. +Need to be separated for grouping: \cite{MeYou2007,YouMe2007}. + +Two spaces (or anything else) for no grouping: \cite{MeYou2007} \cite{YouMe2007}. + +But a line break should work: \cite{MeYou2007,YouMe2007}. + \\begin{thebibliography}{MeYou2007} \\bibitem[MeYou2007]{MeYou2007}{ not. |