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 d39951e
Show file tree
Hide file tree
Showing 3 changed files with 24 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 (`:.#$%&-+?<>~/`). Any illegal character except the first
character of the citekey can be escaped with a `\`. 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.

`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
8 changes: 7 additions & 1 deletion doc/org.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ 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:
(`:.#$%&-+?<>~/`). Any illegal character except the first
character of the citekey can be escaped with a `\`. Alternatively
arbitrary citation keys can be given inbetween `{` and `}`. Inside
them `}` and `\` can be escaped using `\`.

### Simple citation

Expand All @@ -137,9 +140,12 @@ ID prefixed by '@'.

Example:

@citekey
[prefix @citekey suffix]
[see @doe2000 pp. 23-42]
[@doe2000 p. 5; to a lesser extend @doe2005]
@this\ is\ a\ citekey
@{this is a citekey}


LaTeX-Syntax
Expand Down
15 changes: 9 additions & 6 deletions src/Text/Pandoc/Parsing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1468,12 +1468,15 @@ 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 '/')) <|>
char '\\' *> anyChar
pure $ firstChar:rest
<|> char '{' *> many (noneOf "}\\" <|> char '\\' *> anyChar) <* char '}'
return (suppress_author, T.pack key)


Expand Down

0 comments on commit d39951e

Please sign in to comment.