Skip to content

Commit

Permalink
More flexible citation key syntax jgm#6026
Browse files Browse the repository at this point in the history
  • Loading branch information
Aver1y committed May 17, 2020
1 parent 8fc5766 commit 3b8d38b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
9 changes: 8 additions & 1 deletion MANUAL.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4825,14 +4825,21 @@ Each citation must have a key, composed of '@' + the citation
identifier from the database, and may optionally have a prefix,
a locator, and a suffix. The citation key must begin with a letter, digit,
or `_`, and may contain alphanumerics, `_`, and internal punctuation
characters (`:.#$%&-+?<>~/`). Here are some examples:
characters (`:.#$%&-+?<>~/`). Alternatively arbitrary citation keys
can be given inbetween `{` and `}`. Inside them `}` and `\` can be escaped
using `\`. Here are some examples:

Blah blah [see @doe99, pp. 33-35; also @smith04, chap. 1].

Blah blah [@doe99, pp. 33-35, 38-39 and *passim*].

Blah blah [@smith04; @doe99].

You can also use citation keys directly without brackets:

Blah blah @smith04.
@{A more complex cite key}

`pandoc-citeproc` detects locator terms in the [CSL locale files].
Either abbreviated or unabbreviated forms are accepted. In the `en-US`
locale, locator terms can be written in either singular or plural forms,
Expand Down
6 changes: 5 additions & 1 deletion doc/org.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ the citation identifier from the database, and may optionally
have a prefix, a locator, and a suffix. The citation key must
begin with a letter, digit, or `_`, and may contain
alphanumerics, `_`, and internal punctuation characters
(`:.#$%&-+?<>~/`). Here are some examples:
(`:.#$%&-+?<>~/`). Alternatively arbitrary citation keys can be
given inbetween `{` and `}`. Inside them `}` and `\` can be
escaped using `\`.

### Simple citation

Expand All @@ -137,6 +139,8 @@ ID prefixed by '@'.

Example:

@citekey
@{this is a citekey}
[prefix @citekey suffix]
[see @doe2000 pp. 23-42]
[@doe2000 p. 5; to a lesser extend @doe2005]
Expand Down
14 changes: 8 additions & 6 deletions src/Text/Pandoc/Parsing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1468,12 +1468,14 @@ citeKey = try $ do
guard =<< notAfterString
suppress_author <- option False (True <$ char '-')
char '@'
firstChar <- alphaNum <|> char '_' <|> char '*' -- @* for wildcard in nocite
let regchar = satisfy (\c -> isAlphaNum c || c == '_')
let internal p = try $ p <* lookAhead regchar
rest <- many $ regchar <|> internal (oneOf ":.#$%&-+?<>~/") <|>
try (oneOf ":/" <* lookAhead (char '/'))
let key = firstChar:rest
key <-
do firstChar <- alphaNum <|> char '_' <|> char '*' -- @* for wildcard in nocite
let regchar = satisfy (\c -> isAlphaNum c || c == '_')
let internal p = try $ p <* lookAhead regchar
rest <- many $ regchar <|> internal (oneOf ":.#$%&-+?<>~/") <|>
try (oneOf ":/" <* lookAhead (char '/'))
pure $ firstChar:rest
<|> char '{' *> many (noneOf "}\\" <|> char '\\' *> anyChar) <* char '}'
return (suppress_author, T.pack key)


Expand Down

0 comments on commit 3b8d38b

Please sign in to comment.