3

How do you tell LaTeX which alpha key to give a bibliography entry without modifying the .bst file?

Example: I want an entry with

author = {no one 910 (StackOverflow User 118593)}

to appear as [StO17], instead of [noSU17].


Working tex file:

\documentclass{article}

\begin{document}
Hereby I cite \cite{myself}.

\bibliographystyle{alpha}
\bibliography{bibliography}
\end{document}

bibliography.bib:

@misc{myself,
  author = {no one 910 (StackOverflow User 118593)},
  title = {{StackOverflow Answer}},
  howpublished = "https://stackoverflow.com",
  year = {2017}
}

Output:

ugly bib key

yspreen
  • 132

2 Answers2

2

This would be very easy with biblatex:

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@misc{myself,
    shorthand = {StO17},
  author = {no one 910 (StackOverflow User 118593)},
  title = {{StackOverflow Answer}},
  howpublished = "https://stackoverflow.com",
  year = {2017}
}
\end{filecontents*}

\usepackage[style=alphabetic]{biblatex}
\addbibresource{\jobname.bib}

\begin{document}
Hereby I cite \cite{myself}.

\printbibliography
\end{document}

enter image description here

0

Since nobody wants to do things the proper way, here is a hack:

  1. This works only with Authors that do not contain a word that starts with a lower-case letter
  2. Append \Bibkeyhack StO to your author, with StO being the key.

Command definition: (That's all!)

\newcommand{\Bibkeyhack}[3]{}

If you want keys with a different length, replace 3 with your length.
For 1. there is a workaround:

\newcommand{\SmallHack}[1]{\lowercase{#1}}

Notice that both commands start upper-case, so that rule 1. is not violated.

Working example:

author = {\SmallHack No \SmallHack One 910 (StackOverflow User 118593)\Bibkeyhack StO}

Which will result in [StO17]: no one 910. Image proof: bibkey hack

Important: If you put a space between ) and \Bibkeyhack, the result will look like this:

ugly bibkey hack


Complete tex file:

\documentclass{article}

\newcommand{\SmallHack}[1]{\lowercase{#1}}
\newcommand{\Bibkeyhack}[3]{}
\begin{document}
Hereby I cite \cite{myself}.

\bibliographystyle{alpha}
\bibliography{bibliography}
\end{document}

bibliography.bib:

@misc{myself,
  author = {\SmallHack No \SmallHack One 910 (StackOverflow User 118593)\Bibkeyhack StO},
  title = {{StackOverflow Answer}},
  howpublished = "https://stackoverflow.com",
  year = {2017}
}

Output:

better bib key

yspreen
  • 132