1

I'd like bibtex-clean-entry to change a few strings within titles for me - for example I'd like it to replace "CO2" with "CO$_2$". Setting up variable bibtex-field-strings-alist like this

(setq bibtex-entry-format '(opts-or-alts required-fields numerical-fields strings))
(setq bibtex-field-strings-alist
      '((("title") "CO2" "CO$_2$")))

replaces "CO2" with "} # CO$_2$ # {". Close but no cigar. I suspect the unwanted braces and hashes have to do with the definition of "BibTeX string constant" in the docs for bibtex-field-strings-alist, but I'm not spotting anything about what that means.

1 Answer 1

0

[Disclaimer: I don't know much about BibTeX or bibtex.el, so take what follows with the appropriate grain of salt]

I think you misunderstand what this is supposed to do. BibTeX string constants are basically abbreviations:

@string{ foo = "a very long string that I would not like to have to type constantly" }

You can then use it in a field like this:

@Book{ key
   author = {A.U.Thor}
   title  = {This is } # foo # { indeed}
   ...
}

The hash is a string concatenation operator and the string constant foo gets replaced by its definition when you bibtex your file.

What the bibtex-field-strings-alist mechanism allows you to do is to not worry about what's inside and what's outside the braces or getting the string concatenation operators right. You can say

(setq bibtex-field-strings-alist
      '((("title") "foo" "foo")))

and write the entry as

@Book{ key
   author = {A.U.Thor}
   title  = {This foo indeed}
   ...
}

Then C-c C-c gets you the previous form of the entry which is then properly expanded using the definition of the string. That's all it does.

bibtex.el provides some facilities but to understand where/when/how to use them, you need a grounding in BibTeX itself. This question is just barely about Emacs: it's more about BibTeX, so it would probably be more appropriate for the TeX-LaTeX SE site.

PS. BTW, when you change bibtex-field-strings-alist (or as in your previous question, bibtex-field-braces-alist), you don't need to restart emacs, but you do need to reinitialize the variable bibtex-field-strings-opt (or bibtex-field-braces-opt) to nil.

2
  • Thanks, this is really helpful. I did indeed misunderstand what a BiBTex string constant is/does/is for. The phrase "BiBTex string constant" shows up in the documentation for bibtex-field-strings-alist and, as far as I can tell, no where else. Your post filled in my knowledge gap - thanks! Commented Mar 2, 2022 at 22:10
  • I still believe this is an emacs, not a BibTeX question. What I want is for bibtex-clean-entry (an emacs/bibtex.el function) to replace "CO2" with "CO$_2$" in addition to everything else it already does. I had hoped setting up bibtex-field-strings-alist could accomplish this; I see now that's not really what it's for. I guess I'll have to dust off my elisp coding skills. elisp is definitely not my strong suit so I'd hoped there was a pre-canned way to accomplish this. Cheers :) Commented Mar 2, 2022 at 22:14

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.