jrblevin / markdown-mode

Emacs Markdown Mode
http://jblevins.org/projects/markdown-mode/
GNU General Public License v3.0
897 stars 163 forks source link

Syntax highlighting for pandoc-citeproc in-text citations is not working properly when the author name is outside parentheses #424

Open aidengindin opened 4 years ago

aidengindin commented 4 years ago

Expected Behavior

If I have an in-text citation, such as @smith [p. 19] says, only the citation itself (not the following text) should be highlighted.

Actual Behavior

When there is an in-text citation with the author's name outside parentheses followed by a page number, such as the example above, and then another citation later in the same paragraph, all the text in between the citations gets highlighted as if it were part of one big citation.

image

Steps to Reproduce

  1. Add an in-text citation with the author's name outside parentheses and a page number
  2. Add another citation later in the same paragraph

Backtrace

Software Versions

pascalsiemsen commented 4 years ago

Excuse the off-topic content: how do you even get the highlighting for in-text citations?

I checked the font-lock faces for markdown and didn't see it. My citation keys were also not highlighted. At the moment I am experimenting with adding my own font-lock key words (e.g. everything that is in square brackets or starts with an @.

aleneum commented 4 years ago

@pascalsiemsen

At the moment I am experimenting with adding my own font-lock key words (e.g. everything that is in square brackets or starts with an @.

I did not find a built-in solution as well so I went the way of adding a font-lock. You probably figured it out by now but since I stumbled upon this issue when I asked myself exactly the same question, I will leave my solution here:

(defvar markdown-mode-keywords nil)
(setq markdown-mode-keywords
  '(("\\[@[^]]+\\]" . font-lock-keyword-face)
    )
  )

(font-lock-add-keywords
 'markdown-mode
 markdown-mode-keywords
 )

Basically match everything between brackets starting with an '@' which is not a closing bracket itself (to prevent greedy matching two or more references). I also stumbled upon this gist about how to use reftex to achieve pandoc-compatible citations with bibliography lookup.

pascalsiemsen commented 4 years ago

I found a built-in way of highlighting citations:

pandoc-mode

pandoc-mode adds font lock keywords for citations and numbered example lists. The relevant faces can be customised in the customisation group pandoc.

The issue mentioned here is still there though.

ffsammak commented 1 year ago

I recently stumbled upon a thread and was wondering about the most effective method for implementing font locking for pandoc citations within markdown-mode on Emacs. Which specific face is associated with this when using the command M-x list-faces-display? Unfortunately, using C-u C-x = did not provide any helpful information. Can you provide guidance on how to customize the font lock for citations without brackets, indicated by [@ref..]? Your assistance would be greatly appreciated.