Open jeksterslab opened 5 years ago
Since the citation keys bookkeeping and citation rendering are handled by two well separated parts of the application, there's no straightforward way to automate this.
However, you can use the suffix
option to obtain the desired result:
I used cite:[Cheung_2009a, suffix=a] but also cite:[Cheung_2009b, suffix=b].
renders to
I used (Cheung, 2009a) but also (Cheung, 2009b).
@jeksterslab does this solve the problem?
Using cite:[Cheung_2009a, suffix=a] and cite:[Cheung_2009b, suffix=b].
renders to
Using (Cheung, 2009a) and (Cheung, 2009b).
which is great!
However,
Using Cheung citeyearpar:[Cheung_2009a, suffix=a] and Cheung citeyearpar:[Cheung_2009b, suffix=b].
renders to
Using Cheung (2009, a) and Cheung (2009, b).
Is there a way to make it
Using Cheung (2009a) and Cheung (2009b).
?
Also the bibliography entries for Cheung_2009a
and Cheung_2009b
render to
Cheung, M. W.-L. (2009). Comparison of Methods for Constructing Confidence Intervals of Standardized Indirect Effects. Behavior Research Methods, 41(2), 425–438. https://doi.org/10.3758/brm.41.2.425
Cheung, M. W.-L. (2009). Constructing Approximate Confidence Intervals for Parameters With Structural Equation Models. Structural Equation Modeling: A Multidisciplinary Journal, 16(2), 267–294. https://doi.org/10.1080/10705510902751291
As per APA, they should be
Cheung, M. W.-L. (2009a). Comparison of Methods for Constructing Confidence Intervals of Standardized Indirect Effects. Behavior Research Methods, 41(2), 425–438. https://doi.org/10.3758/brm.41.2.425
Cheung, M. W.-L. (2009b). Constructing Approximate Confidence Intervals for Parameters With Structural Equation Models. Structural Equation Modeling: A Multidisciplinary Journal, 16(2), 267–294. https://doi.org/10.1080/10705510902751291
Any workaround would be greatly appreciated.
I've checked the APA CSL style:
disambiguate-add-year-suffix
year-prefix
es and enables disambiguate-add-year-suffix
(see https://editor.citationstyles.org/styleInfo/?styleId=http%3A%2F%2Fwww.zotero.org%2Fstyles%2Fapa)However the rendered we're using (citeproc-ruby
) still hasn't enabled the feature, if I'm not mistaken (see https://github.com/inukshuk/citeproc-ruby/blob/50764e6f448f9f7d61cd8e246c8ab2f73a8d3ac2/spec/citeproc/ruby/renderer/choose_spec.rb#L71)
I see no easy workarounds, unfortunately.
I think we could either
year-prefix
, which probably isn't that much simpler and might have unwanted side effects.Hi folks, I want to second the motion made by jeksterslab. Just to throw in my two cents, I would say this glitch is pretty serious. I hope it can be fixed. Cheers, Andy
I've attached my attempt at a fairly simple-and-quick workaround-solution, in XSLT 2.0. You run this transform on the results of your Asciidoctor-generating.
This one is for applying to an AsciiDoc document aimed at HTML (like the one @jeksterslab was working on). For that, you need to use Asciidoctor's XHTML back-end on the document, and then apply this XSLT transform to the XHTML result -- which will output a fully HTML file. (I have a different version that works on Asciidoctor-generated DocBook XML, if anyone needs it.)
There is a longish comment at the top of the file, describing (I believe) the exact assumptions this transform makes about the bibliography-items in the generated bibliography it's working with, and about the citations. (E.g., it assumes author-year citations, and that bibliography-items have the year following the author-name(s).) I tested it on an APA example (like jeketerslab's) and on one of my own, Chicago-style bibliographies.
Also the comment gives instructions for how to use this XSLT transform on a document with multiple bibliographies.
This is standard XSLT 2.0: I ran it on Saxon-HE (a very competent, free, Java-based XSLT processor). It would probably have trouble working on MSXML, which has some special syntax it requires.
Issue_106,asciidoctor-bibliography_XHTML.zip Let me know if you have any questions about it.
P.S. It is likely important to clarify one thing:
I hope that helps.
Testing of what would happen if one applied my transform to a bibliography multiple times revealed some undesirable results :/ I've fixed that problem and re-attached.
Some helpful links:
NOTE that those instructions assume you have made Saxon's Java files available on your CLASSPATH. If you don't want to bother with that, just use the -cp option on your command line with a filepath to Saxon-HE's jar-file. Your command line would then look something more like:
java -cp C:\Users\acarver\Dropbox\XML\Saxon\HE9-9-1-4J\saxon9he.jar net.sf.saxon.Transform -s:<source-file> -xsl:<your_stylesheet> -o:<your_output_filename> bib-id="foo"
Another update: Discovered the much better way - instead of the way I was using - to fix the excess white-spacing in the HTML output (Saxon was inserting blank lines between elements, on top of indenting). So, replaced my overkill <xsl:strip-space>
with an indent="no"
attribute on <xsl:output>
.
(Also, changed instructions on using the latter element's method
attribute: the value 'xhtml' works only for some processors; instead, just use 'xml'; but again, use 'html' for your last/lone transformation.)
In case someone can use it, here's also the transform for fixing up DocBook-XML output.
Issue_106,asciidoctor-bibliography_XHTML.zip Issue_106,asciidoctor-bibliography_DocBook-XML.zip
A little upgrade: Although this XSL-transform approach to addressing Issue 106 seems effective, it is (as implemented above) also tedious and rather tricky: Not only do you have to run the XSLT transform on your source-file (XHTML or DocBook XML) once for each separate bibliography in it; you must also manually enter the correct bibliography-id (even if you pass it as a parameter) for each run.
One solution to those problems is to automate the process as an XML pipeline, using XProc. In fact, if you're using the Calabash (open source) XProc engine to run your pipeline,, there's a way to get the pipeline to check out how many bibliographies your source file has -- with what bib-ids -- and then generate a suitable XProc pipeline on the fly -- and apply it.
This approach involves two more files for each source-file type (XHTML and DocBook XML), alongside the XSL transform I posted above,. That makes six files in all, for this, uh, "solution" to Issue 106.
The attached zip file contains what we might call "stub" versions of these six files. I'd suggest that you place all six files in one folder. The XProc (*.xpl) file is the one you want to run; it will bring in the other two on its own. (The XPL files' filenames end in "_DYNAMIC.xpl".)
To prepare these "stub" files for use, you'll have to adjust several filepaths to mirror your directory-structure: I've inserted comments at the points where the adjustments are needed, to indicate what sort of filepath is needed in each place. Please make these changes in the two XPL files I've mentioned, as well as in those (two) XSLT files whose names end in "-pipe-generating.xsl".
If you're working on the HTML side of things, please remember that you want Asciidoctor to generate XHTML - not HTML. (Nothing to worry about here: the XHTML pipeline file will serialize the final output as HTML). And remember that BOTH these pipelines are written for Calabash -- I think I can promise you they won't work on another XProc engine!
I hope this helps. Please let me know if you have questions or issues.
Ouch -- I apologize: A few of those filepath-comments I mentioned, I had zealously pasted in but not carefully edited! I've now done the latter as well:
Every day, in every way, I'm freeing those comments of errors...
Efficiency-improvemenbts (significant), some commenting that should help folks unfamiliar with XSLT, and some minor code-cleanup for intelligibility, in the XSLT transforms that do the actual year-suffixing work:
Fixed a serious bug in the "pipe-generating" XSLT files: now, any detected AsciiDoc bibliography with @id (or @xml:id) = simply "_bibliography" will be assigned the proper bibliography-id "default".
Now I've found an (ahem) "more reliable" assumption to make, though -- for sadly, it seems impossible not to make SOME assumption -- to support this "bib-ID" detection by two "pipe-generating" XSLT files (one for DocBook, one for XHTML):
The assumption now is (simply?!) that no resource-key -- for a bibliographic resource cited -- contains a hyphen.
As long as that assumption holds true, then the XSLT can divine from the XML source-file, what the bib-IDs are, by looking directly at what target-params have been used in bibliography::[]
macros (e.g., bibliography::foo[]
).
Obviously, within the XML generated, that macro is no longer present. However, its "target" param-value appears in the @id or @xml:id values of all bibliography-entries that have been generated and gathered together for that bibliography. However, precisely because that bibliography-macro is now gone, we have no way (given only the generated XML) to glean what the target-value was, EXCEPT by making the above assumption (of no-hyphens-in-keys).
If you find that assumption impossible to support in your practice, please use the version posted Oct. 9, 2019 (before the "pipeline-generating" approach was introduced); you'll just have to convert each bibliography one at a time, specifying manually the bibliography's ID.
Issue_106,asciidoctor-bibliography_XProc--pipelines.zip
P.S. However, for those NOT FAINT OF HEART, I offer an alternative assumption. In fact, for such brave souls, a simple operation of commenting-one-line-out and commenting-another-line-in, in the below archive's pipe-generating .XSL files, will change the assumption -- and those lines, and their respective assumptions, are marked therein.
This alternative assumption that some might be able to live-with better than the one mentioned above (about no hyphens in resource-keys), is:
That means, you CAN'T use foo-bar
or Indian-wars
or any other hyphenated term as a target of your bibliography::[]
macro (i.e. bibliography::foo-bar[]
is verboten). In any case, the below version is probably better to download than the above, since its pipeline-generating files contain the internal documentation for how to change assumption. (As packaged therein, the pipe-generating .XSLs have the "no-hyphens-in-resource-keys" assumption operative.)
Ok, this one will be the version to use if you're going the "pipe-generating" (automatic-bib-ID-detecting) route. But in addition to needing to-comment-one-line and to-uncomment-one-line in the "pipe-generator" file(s), in case of assumption-change, you will need to do that also in the other .XSL file(s) -- where these two code-lines are likewise marked.
N.B. Whenever you change the assumption in either of the DocBook-XML-targeting .XSL files, you must change it in the other as well -- keeping them in sync:
Issue_106,asciidoctor-bibliography_DocBook-pipe-generating.xsl
Issue_106,asciidoctor-bibliography_DocBook-XML.xsl
-- and, the same goes for the XHTML-targeting .XSL files:
Issue_106,asciidoctor-bibliography_XHTML-pipe-generating.xsl
Issue_106,asciidoctor-bibliography_XHTML.xsl
(Both for the two XHTML-targeting .xsl files, and for the two DocBook-XML-targeting .XSL files, the assumption currently active is "no-hyphens-in-resource-keys".)
Issue_106,asciidoctor-bibliography_XProc--pipelines.zip
And, P.S.:
Since this and other significant improvements have been made to those two NON-pipe-generating .XSL files -- and since those are the files one uses when going the "static" (i.e., MANUALLY-specifying-the-bib-ID(s)) route -- I've re-packaged them separately, here; and folks going this "static" route should use these updated versions, instead of the ones posted Oct. 9, 2019:
Issue_106,asciidoctor-bibliography_XHTML.zip Issue_106,asciidoctor-bibliography_DocBook-XML.zip
Perhaps (but hopefully!) my last improvement, to this proof-of-concept XSLT fix of this Issue:
In each of the two main XSLT files (for transforming XHTML and DocBook XML, respectively), I had included this statement in the comments at the top:
[This stylesheet] assumes that your bibliography-entry style puts year right after author(s).
For example:
<simpara><anchor xml:id="bibliography-default-Lonergan1973" xreflabel="[bibliography-default-Lonergan1973]"/>Lonergan, Bernard J. F., S. J. 1973. <emphasis>Method in Theology</emphasis>. Second edition. London: Darton, Longman & Todd.</simpara>
The comment continued:
It assumes [also, that] your citation-style is doing author-year. (This could PROBABLY be altered.) It does allow author-only citations: it will append NO year-suffix to such citations.
So, until now these stylesheets assumed a very substantial restriction of the wide range of citation-styles which asciidoctor-bibliography supports. :-/
What I've done in the new versions of these two files, is to fix (as far as I can) this assumption about citation-style. I've done this by making use of the assumption mentioned (viz. that the year shows up in the bibliography-entry -- right after the author(s)' name(s)); grabbing the year from THERE; and then looking to see whether that year shows up ANYWHERE REASONABLE within the citation. If and only if it finds it in the citation, does it further check whether that year-mention needs a suffix -- and if so, append it.
P.S. There's also a slight improvement to the robustness of the bibliography-item-matching template (which is the rule-template that puts any needed year-suffix within the bibliography-item).
P.P.S. The one situation in which you must be careful, in order to make sure the citation's year-suffixing goes as it should, is where the citation contains two or more occurrences of the work's year-number -- e.g., the (unlikely) situation in which that year-nr is also the page-nr being cited, or in which it occurs in the title of the work (and the title also appears, somehow). By an "occurrence", I mean that the year-nr is separated from any other text by a space-character(s) -- or, optionally by a comma, following the year-nr.
In any such situation, it is only the FINAL occurrence of the year-nr that will be checked, as to whether it needs a suffix. So, one must make sure that the structure of the citation is such that the occurrence which mentions the actual year of the work (and not, say, the page-nr of interest), is the one that appears AFTER all others.
That can always be done, if only by using one of the citation-forms which gives you utmost flexibility in citation-structure: e.g.,
cite:[Lonergan1973, prefix="see p. 1973 of "]
or
cite:[Lonergan1973, text="see pg. 1973 in Lonergan 1973"]
N.B. If the work's actual year-nr (as shown in its bibliography-item) appears AT ALL in the citation (even if only as, say, a page-nr), ITS LAST OCCURRENCE WILL be checked, for whether it needs a suffix.
I have two bibliography entries in my
.bib
file with the same author and year of publication (see below). I typically appenda
andb
on thekey
to distinguish the entries (e.g.,Cheung_2009a
andCheung_2009b
). When I convert theAsciiDoc
tohtml
usingasciidoctor -r asciidoctor-bibliography text.adoc
both entries are referred to asCheung, 2009
on thehtml
document. Is there a way form me to haveCheung, 2009a
andCheung, 2009b
on thehtml
document instead of havingCheung, 2009
for both entries? I am using:bibiliography-style: apa
. Thanks very much for this very useful extension.@Article{Cheung_2009a, author = {Mike W.-L. Cheung}, title = {Comparison of Methods for Constructing Confidence Intervals of Standardized Indirect Effects}, number = {2}, pages = {425--438}, volume = {41}, date = {2009}, doi = {10.3758/brm.41.2.425}, journaltitle = {Behavior Research Methods}, publisher = {Springer Nature}, }
@Article{Cheung_2009b, author = {Mike W.-L. Cheung}, title = {Constructing Approximate Confidence Intervals for Parameters With Structural Equation Models}, number = {2}, pages = {267--294}, volume = {16}, date = {2009}, doi = {10.1080/10705510902751291}, journaltitle = {Structural Equation Modeling: A Multidisciplinary Journal}, publisher = {Informa {UK} Limited}, }