7

The bibtex-fill-entry (C-c C-q) command of Emacs's BibTeX-Mode automatically aligns and wraps messily formatted BibTeX entries. For example, it can take an entry like

@Article{smith1980,
author = {John Smith},
  title = {How I Weave Baskets Underwater},
 journal =  {Journal of
  Underwater Basket
Weaving and Nonsensical Latin Placeholder Texts},
  year = 1980,
abstract = {Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
  Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.},
}

and beautify it into

@Article{smith1980,
  author =       {John Smith},
  title =        {How I Weave Baskets Underwater},
  journal =      {Journal of Underwater Basket Weaving and Nonsensical
                  Latin Placeholder Texts},
  year =         1980,
  abstract =     {Lorem ipsum dolor sit amet, consectetur adipiscing
                  elit, sed do eiusmod tempor incididunt ut labore et
                  dolore magna aliqua. Ut enim ad minim veniam, quis
                  nostrud exercitation ullamco laboris nisi ut aliquip
                  ex ea commodo consequat.  Duis aute irure dolor in
                  reprehenderit in voluptate velit esse cillum dolore
                  eu fugiat nulla pariatur. Excepteur sint occaecat
                  cupidatat non proident, sunt in culpa qui officia
                  deserunt mollit anim id est laborum.},
}

I like the fact that the fields and values are aligned, but I would prefer it if the values were not word-wrapped. That is, I would prefer it if the output of bibtex-fill-entry on the above example were

@Article{smith1980,
  author =   {John Smith},
  title =    {How I Weave Baskets Underwater},
  journal =  {Journal of Underwater Basket Weaving and Nonsensical Latin Placeholder Texts},
  year =     1980,
  abstract = {Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.  Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.},
}

This allows me to more easily browse long BibTeX files with toggle-truncate-lines, or with any other text editor that truncates rather than wraps long lines. Is there any way I can configure BibTeX-Mode to do this?

4
  • This is more a question towards emacs than BibTeX. Maybe the emacs.SE-Group will be more adequate? Chances are, that there will be a better answer in shorter time?
    – Jan
    Dec 22, 2016 at 10:27
  • Maybe emacs.stackexchange.com/questions/24885/… is nearly the function, you are looking for?
    – Jan
    Dec 22, 2016 at 10:32
  • @Jan: I don't think so. I do want to avail myself of all the other formatting that bibtex-fill-entry does, such as removing extraneous braces. I just don't want it to wrap lines. From what I can tell, the function you linked to performs indentation only – I don't think it even bothers unwrapping lines, let alone any other tweaking.
    – Psychonaut
    Dec 22, 2016 at 10:37
  • Nice to know about that functionality. I'm using JabRef for entry formatting, When an entry is changed, JabRef reformats the whole entry. There is also a button "push-to-application" for getting \cite{key} into emacs.
    – koppor
    Dec 23, 2016 at 7:06

1 Answer 1

10

Just set fill-column to something ridiculously large (like 999999).

The command C-x f (M-x set-fill-column RET) does this (prompts for a number).

To get this as default, add this to your .emacs file (or whatever has this function in your Emacs):

(add-hook 'bibtex-mode-hook
             (lambda () (setq fill-column 999999)))
6
  • I don't quite follow, what do you mean by ^X here?
    – daleif
    Dec 22, 2016 at 11:31
  • 1
    He means C-x or Control+X.
    – Psychonaut
    Dec 22, 2016 at 11:52
  • @Psychonaut but normally C-x is a prefix. I usually use M-x set-variable RET fill-column to set this value. So I was curious if there was an easier method
    – daleif
    Dec 22, 2016 at 12:30
  • 1
    Well, now you've got one. Or at least, I do – C-x f works for me, as does putting the hook in my .emacs.d/init.el file.
    – Psychonaut
    Dec 22, 2016 at 13:13
  • Great idea, Piet! And so simple!
    – Jan
    Dec 22, 2016 at 13:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .