0

I was wondering how to go about incorporating a bib style file into a custom package so that it does not have to be stipulated separately in the body of every document.

Specifically, I currently use natbib and call on sp.bst by placing \bibliographystyle{C:/Users/Miztli/Documents/BibTeX/sp} before \bibliography{C:/Users/Miztli/Documents/BibTeX/references} at the end of my documents.

  • I'm having difficulty understanding what you want to achieve? My first instinct is that this business of encoding fixed paths containing data in a style file smells wrong. It might help to explain what you are trying to do. Is it just to save a little typing? Or is there some deeper objective? – Paul Stanley Apr 18 '17 at 21:45
  • I'm hoping to create a personal package which loads those packages and settings used in all my documents with a single line of code rather than thirty or so. I don't think creating a custom class is not going to be appropriate since I'd like to use this in at least book, article and beamer classes. So, in essence, yes, I'm trying to save typing (or copying-and-pasting). – Miztli Apr 18 '17 at 21:49
1

To me it doesn't seem right to try to build this sort of thing into a .sty file. Even making allowances for some flexibility/laxness with personal style files, it seems dubious practice to make them contain hard-coded paths to other data sources. Besides, as you point out, there are obvious difficulties doing that for a bibliography, because of where it wants to be loaded.

I'd prefer (in rough order):

  1. Use an editor which can insert a snippet. In Emacs, for instance, with yasnippet, one could easily define something so that expanded suitably. Then each file you produce is transparent about what resources it is using. You save typing, but each file you produce remains reasonably self-contained. That's good in the long term. Although it seems like a good idea to have a style file, you will get in a hell of a mess if, at some point in the future, you lose it or change it and forget how or why or when you changed it.

  2. Put your bibliography definitions in a separate file which you simply \input at an appropriate point. But really ... what's the point. You really will be saving a few keystrokes.

  3. If you really must put this in a .sty file, do so by defining a suitable command of your own (\makemybibliography or something) which will expand to the commands you want, preferably with suitable prior checks that the files you need exist where you expect them to be, and suitable errors if they don't. Doing that properly is probably a lot more work than writing a snippet for an editor.

1

The \bibliographystyle command can go anywhere, AFAIK. It doesn't have to go at the end before the \bibliography command. So you could put it in your package or class.

  • And probably disable \bibliographystyle so it can no longer be used. – egreg Apr 18 '17 at 21:34
  • Perhaps I should've been clearer: Is there a way of including the bib style file within the custom package such that it is not dependent on a separate file on the computer or is there a way of bundling the bib style file with the package? – Miztli Apr 18 '17 at 21:37
  • 1
    Ah, OK, sorry, I misunderstood. Yes there is, but see my additional answer. – Peter Flynn Apr 20 '17 at 7:49
1

Yes, you can bundle an additional file into your package (it isn’t possible to embed .bst code in a .sty file in any meaningful manner because it’s written a different language).

You have to write it as a .dtx file in the standard way for distributable packages, so that when the user installs it, it will unwrap your .sty file and the .bst file you included (and more files, if needed). The user then has to put those files in “the right place”, which is explained here, exactly as for every other package installed manually.

BUT...(very big BUT), if the BiBTeX style file is already a standard package on CTAN (I can’t find it there), then bundling a private copy in your package is A Very Bad Idea indeed. The user should install it from CTAN in the normal way (if they’re using a TeX distribution with on-the-fly installation, this may just get done for them automatically).

Is this sp.bst the one from Semantics & Pragmatics? If so, you should encourage them to have it properly bundled and made available through CTAN if they can, which would make life easier for everyone. In any case you can certainly add it to your .dtx file, but you would need permission from the author or copyright holder to do so, and you’d need a formal agreement to handle updating and overwriting.

Paul Stanley makes some good points, but

  1. IMHO it is a good idea to make a formal package (.sty) file, but only when written as a .dtx file with proper documentation so it can be installed, maintained, and referred to;
  2. I’m not sure I understand why 2 is useful at all;
  3. apart from Emacs, I don’t know any LaTeX editors that support snippets, and it’s not a good idea to force authors to use an editor different from the one they normally use.

Consider moving away from BiBTeX to biblatex (but if this sp.bst file is S&P’s then you’d need to persuade them to do this).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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