3

In the context of biblatex its possible to bibstyle=reading, this will produce bibliography including abstract and annotation fields.

The annotation might come from a file named like bibannotation-TheBook2019.tex where TheBook2019 is the bib file entry key.

@book{TheBook2019,
 author     = {The Author},
 title      = {The Book Title}
}

The annotation file bibannotation-TheBook2019.tex can contain latex formated text. One might then \input{bibannotation-TheBook2019.tex} somewhere in a document. And so might be appropriate to include a citation in the bibannotation-TheBook2019.tex. Is this case it willl be self citation, I mean that file will refer to the respective entry key:

\cite{TheBook2019}

Since this information is in the file name. Can I automate it some way? So that I can just type something like:

\cite{\SelfCite}

And it will be converted to \cite{TheBook2019} grabbing the entry key from file name.

4

You can do this with a couple of helper functions.

\KcFnMiinput saves the name of the key using \filenametokey then inputs the file.

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{TheBook2019,
 author     = {The Author},
 title      = {The Book Title}
}
\end{filecontents}
\begin{filecontents}{annotation-TheBook2019.tex}
This file contains an annotation for \verb|TheBook2019|. It's also possible to
cite it: \cite{\selfcitekey}.
\end{filecontents}
\usepackage{biblatex}
\addbibresource{\jobname.bib}
\def\filenametokey annotation-#1.tex{#1}
\newcommand{\KcFnMiinput}[1]{%
  \edef\selfcitekey{\filenametokey #1}%
  \input{#1}}
\begin{document}
\KcFnMiinput{annotation-TheBook2019.tex}
\printbibliography
\end{document}

output

| improve this answer | |
  • Please, could you update answer so that I can also refer to bib files in another folder, like \input{bib/bibannotation-TheBook2019.tex}? – KcFnMi May 7 '19 at 4:49
  • Can newcommand be used instead of def ? Considering tex.stackexchange.com/questions/655/…. – KcFnMi May 7 '19 at 4:55
  • @KcFnMi It's not possible to use \newcommand for \filenametokey. It (essentially) uses the technique explained in tex.stackexchange.com/a/662/87678. You can modify the template however you want. Just use \def\filenametokey bib/annotation-#1.tex{#1} and then \KcFnMiinput{bib/annotation-TheBook2019.tex}. (This isn't so easy to do in the MWE though, since filecontents can't output to a subdirectory without --shell-escape to create the subdirectory first if it doesn't exist.) – David Purton May 7 '19 at 5:09

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.