emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[wip-cite-new] Adjust punctuation around citations


From: Nicolas Goaziou
Subject: [wip-cite-new] Adjust punctuation around citations
Date: Thu, 13 May 2021 23:33:36 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)

Hello,

Following discussion with Bruce D'Arcus and Denis Maier, I pushed, in
the "wip-cite-new" branch, the first version of a tool for adjusting the
location of the citation and surrounding punctuation according to fixed
rules. The name is `org-cite-adjust-punctuation' and its docstring is:

  Adjust punctuation around CITATION object.

  When CITATION follows a quotation, or when there is punctuation next to it,
  the function tries to normalize the location of punctuation and citation
  according to some RULE.

  RULE is a triplet of symbols (PUNCT POSITION RELATIVE):

    PUNCT is the desired location of the punctuation with regards to the
    quotation, if any.  It may be `inside', `outside', or`strict', the latter
    meaning the punctuation should not be moved.

    POSITION is the desired location of the citation with regards to the
    quotation, if any.  It may be `inside' or `outside'.

    RELATIVE is the relative position of the citation with regards to the 
closest
    punctuation.  It may be `after' or `before'.

  For example,

    (inside outside after) corresponds to American typography;
    (strict outside after) corresponds to German typography;
    (strict inside before) corresponds to French typography.

  INFO is the export state, as a property list.

  Optional argument PUNCT is a list of punctuation marks to be considered.
  When nil, it includes the following: \".\" \",\" \";\" \":\" \"!\" and \"?\".

  Parse tree is modified by side-effect.

  Note: if you are calling both `org-cite-adjust-punctuation' and
  `org-cite-wrap-citation' on the same object, call 
`org-cite-adjust-punctuation'
  first.

Citation processors focused on export may choose to use it, particularly
when using note style. 

As an example, the following code implements a processor named `test'
that uses note style, and adjust punctuation according to the language
specified for the document.

--8<---------------cut here---------------start------------->8---
(defun org-test--language-to-rule (info)
  (pcase (plist-get info :language)
    ("en-us" '(inside outside after))
    ((or "en" "de" "en-gb") '(strict outside after))
    ("fr" '(strict inside before))
    (_ nil)))

(defun org-test-export-citation (citation _style _backend info)
  (pcase (org-test--language-to-rule info)
    (`nil nil)
    (rule (org-cite-adjust-punctuation citation rule info)))
  (unless (org-cite-inside-footnote-p citation)
    (org-cite-wrap-citation citation info))
  "...")

(org-cite-register-processor 'test
  :export-citation #'org-test-export-citation)
--8<---------------cut here---------------end--------------->8---

Once evaluated, you can test it, for example, by exporting the following
document:

--8<---------------cut here---------------start------------->8---
#+language: de
#+cite_export: test

"This is a complete sentence." [cite:@key]

"This is an incomplete sentence" [cite:@key].

This is a complete sentence. [cite:@key]

This is an incomplete sentence [cite:@key].
--8<---------------cut here---------------end--------------->8---

and changing language value.

WDYT?

Regards,
-- 
Nicolas Goaziou



reply via email to

[Prev in Thread] Current Thread [Next in Thread]