PreTeXtBook / pretext

PreTeXt: an authoring and publishing system for scholarly documents
https://pretextbook.org
Other
267 stars 209 forks source link

Allow the user to specify that un-referenced biblio items should not appear in the output #1240

Open alexjbest opened 4 years ago

alexjbest commented 4 years ago

See https://groups.google.com/forum/#!topic/pretext-dev/HDjVhO7t2qM

I made a bad and stupid version of this?:

<!-- As an item of a description list, but       -->
<!-- compatible with thebibliography environment -->
<xsl:template match="biblio[@type='raw']">
    <!-- begin the list with first item -->
    <xsl:if test="not(preceding-sibling::biblio)">
        <xsl:text>%% If this is a top-level references&#xa;</xsl:text>
        <xsl:text>%%   you can replace with "thebibliography" environment&#xa;</xsl:text>
        <xsl:text>\begin{thebibliography}{9}&#xa;</xsl:text>
    </xsl:if>
    <xsl:if test="//xref[contains(@ref,current()/@xml:id)]">
        <xsl:text>\bibitem</xsl:text>
        <!-- "label" (e.g. Jud99), or by default serial number -->
        <!-- LaTeX's bibitem will provide the visual brackets  -->
        <xsl:text>[</xsl:text>
        <xsl:apply-templates select="." mode="serial-number" />
        <xsl:text>]</xsl:text>
        <!-- "key" for cross-referencing -->
        <xsl:text>{</xsl:text>
        <xsl:apply-templates select="." mode="latex-id"/>
        <xsl:text>}</xsl:text>
        <xsl:apply-templates select="." mode="label" />
        <xsl:apply-templates />
        <xsl:text>&#xa;</xsl:text>
    </xsl:if>
    <!-- end the list after last item -->
    <xsl:if test="not(following-sibling::biblio)">
        <xsl:text>\end{thebibliography}&#xa;</xsl:text>
    </xsl:if>
</xsl:template>

note I also changed referencelist to thebibliography. And that this is not controlled by an option, but the real thing should be.

One deficiency of this implementation is when xrefs refer to more than one biblio item using a comma separated list I have tried to use contains for this which looks to be working fine. However it does suffer the issue that if I have

<xref ref="bib-beezer-again>I only care about Blah-II</xref>

....

<biblio xml:id="bib-beezer">Blah</biblio>
<biblio xml:id="bib-beezer-again">Blah-II</biblio>

then both references appear as bib-beezer occurs in both ids. Some proper regex (can you even do regex in xslt) should fix it.

rbeezer commented 4 years ago

Regex is available in XSLT 2.0, which we are not ready to move to.

I convert separators to spaces, use normalize-space() to consolidate and trim, add back a single space at the start and end, then search on terms, etc with spaces on each end. Or instead of spaces, fence strings off with a weird symbol like |.

Spaces work, assuming they are not allowed in identifiers.

I've got some big-picture proof-of-concept working for "assembling" source, but will want to test on existing WeBWorK first (maybe?) since it is harder and will provide better testing.

alexjbest commented 4 years ago

@rbeezer That sounds good, I'm still wondering about numbering. It seems to me the best way to achieve my goal is to have something that runs before any other processing and removes un-ref-ed biblio's from the xml file then, before any other processing starts, rather than ignoring them only at the time the bibliography is created. Do you know if something like this is possible in xslt, and if so are there any examples of similar procedures already in pretext, I'm happy to have a crack at modifying something existing to work, but the prospect of learning the right parts xslt to do this from scratch seems a little daunting (getting the above working took longer than I'd like).

rbeezer commented 4 years ago

Dear Alex,

Did you see the "Assembly" thread on pretext-dev? Lots of details there. And daunting for me. I'm doing something similar (but easier in some respects) with knowls today.

Let me know what questions that thread doesn't answer (even if they are the ones you just asked!).

Rob