0

I'm struggling with using bibtex-field-braces-alist to format titles in Bibtex entries. I've set this as

(setq bibtex-field-braces-alist
      '((("title") . ("N2O" "European"))))

My interpretation of the variable's documentation (below) is that this should cause bibtex-clean-entry to change the title field "Western European N2O emissions" to "Western {European} {N2O} emissions". However, nothing happens for me :( I have added "braces" to bibtex-entry-format:

(setq bibtex-entry-format '(opts-or-alts required-fields numerical-fields braces)) 

bibtex-field-braces-alist’s value is ((("TITLE") "N2O" "European")) Original value was nil

You can customize this variable.

Documentation: Alist of field regexps that C-c C-c encloses by braces. Each element has the form (FIELDS REGEXP), where FIELDS is a list of BibTeX field names and REGEXP is a regexp. Space characters in REGEXP will be replaced by "[ \t\n]+".

1 Answer 1

0

Try

(setq bibtex-field-braces-alist
      '((("title") "N2O\\|European")))

Rationale: a REGEXP is represented by a string, not a list. Here you want a regexp that will match the string "N2O" or the string "European". That is done with the alternation construct \| (see Regexps Backslash in the Emacs manual). Note that backslashes have to be doubled in strings that are to be read by the Lisp reader - see this SE Emacs question for more details on this wrinkle.

Just tested it and it seems to work.

EDIT: In response to your comment about restarting emacs to get the change to take effect, that is one way to do it. The problem is that there is another variable, bibtex-field-braces-opt, that is set from bibtex-field-braces-alist after some munging, but only if that variable is nil. So to get the change to take effect without restarting emacs, you also have to change that variable:

(setq bibtex-field-braces-opt nil)

One good way to avoid such problems would be to use Customize to change bibtex-field-braces-alist, which should be set up to reset the other variable when you change this one by calling bibtex-field-re-init, but AFAICT it is not: that should probably be reported as a bug. Ditto for bibtex-field-strings-alist and bibtex-field-strings-opt.

2
  • Thanks. Good catch on the string/list - I think my brain skimmed "Alist of field regexps" and converted it to "A list of regexps" :) Jan 21, 2022 at 0:43
  • It's also worth noting that I had to restart emacs to get the change to take effect. Evaluating the expression in my .emacs file caused bibtex-field-braces-alist to show the new value when queried, but had no effect on bibtex-clean-entry until after a restart. Jan 21, 2022 at 0:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.