1

I have a Latex file with citation keys which are translated into formatted literature references in the pdf (I use biblatex). Let us assume I want to have the formatted footnotes, as I see them in the pdf text, in the latex file, for whatever reason.

I can only think of the manual solution, I could manually copy each reference in the pdf file, replace the citation key in the latex file with the copied reference, and edit the reference appropriately (for instance include \textit{} for the title of the book etc.)

Is there any smart and faster way to do this?

Edit: I use a bib-file which include the relevant information for the literature references

Edit 2: To clarify: Let's say I use this minimal example and bib file from here (The most basic biblatex example)

\documentclass[a4paper,11pt]{article}
\usepackage[style=numeric,backend=biber]{biblatex}
\addbibresource{\jobname.bib}
\begin{document}
As first example citation here is \cite{Chomsky1957}. 
Here is another example citation \cite{Labov1972}
\printbibliography
\end{document}

Here is the Bib File

\begin{filecontents}{\jobname.bib}
@book{Labov1972,
    Address = {Philadelphia},
    Author = {William Labov},
    Publisher = {University of Pennsylvania Press},
    Title = {Sociolinguistic Patterns},
    Year = {1972}}

@book{Chomsky1957,
    Address = {The Hague},
    Author = {Noam Chomsky},
    Publisher = {Mouton},
    Title = {Syntactic Structures},
    Year = {1957}}
\end{filecontents}

When I compile the PDF I will receive a formatted citation

enter image description here

Is there any smart way to replace in the Latex file the citation key "\cite{Chomsky1957}" with the formatted reference that can be found in the PDF (Chomsky, Noam, 1957, Syntactic Structures. Mouton, The Hague.)

The aim would be to have a latex file which already contains the formatted references

4
  • 1
    It's not entirely clear what you are asking here - you want what would normally be a citation to look like a full reference as would normally be found in the bibliography?
    – PLK
    Sep 2, 2022 at 9:02
  • 1
    seems related: tex.stackexchange.com/questions/435658/…
    – cmhughes
    Sep 2, 2022 at 9:49
  • 1
    Basically no. biblatex typesets the citations (and bibliography entries) in such a way that the equivalent "plain-text LaTeX code" is not easily accessed (it might be possible to export and re-import LaTeX into different formats). There is biblatex2bibitem as a workaround that works OK in many simple cases (tex.stackexchange.com/q/624703/35864), but it is by no means universal.
    – moewe
    Sep 2, 2022 at 10:16
  • Ok, thank you all!
    – Guest4
    Sep 2, 2022 at 10:19

1 Answer 1

1

I don't have a biblatex solution, because referencing Create text-file of references we see that

there is no easy way to obtain the text of the bibliography as it is printed by \printbibliography

So, this solution focuses on the bibtex part from the above link, using plain-plain.bst from https://gist.github.com/moewew/50795d6f171269e949d71d8c4149468e.

myfile.tex (your mwe modified slightly)

I'm using the following modified version of your file, which does not use biblatex.

% arara: pdflatex
% arara: bibtex
% arara: pdflatex
% arara: pdflatex
\documentclass[a4paper,11pt]{article}


\begin{document}
As first example citation here is \cite{Chomsky1957}. 
Here is another example citation \cite{Labov1972}

\bibliographystyle{plain-plain}
\bibliography{\jobname.bib}

\end{document}

plain-plain.bst (slightly modified version)

I'm using plain-plain.bst (linked above) with the following modification:

...
FUNCTION {output.bibitem}
{ newline$
  ""
  newline$
  "bib-key-begin---" write$
  cite$ write$
  "---bib-key-end" write$
  newline$
  before.all 'output.state :=
}
...

I put this file in ~/texmf/bibtex/bst/plain-plain.bst and ran texhash ~/texmf

This means that I run the mwe, then I receive

myfile.bbl

bib-key-begin---Chomsky1957---bib-key-end
Noam Chomsky. Syntactic Structures. Mouton, The Hague, 1957.


bib-key-begin---Labov1972---bib-key-end
William Labov. Sociolinguistic Patterns. University of Pennsylvania Press,
  Philadelphia, 1972.

This is a plain text version of the bibliography. From here, we need to read this into the .tex file and replace the \cite{<key>} with the appropriate value.

You can use any kind of text processing for this; I'd use latexindent.pl (disclaimer, I'm the author) and the following file:

latexindent.yaml


replacements:
  -
    when: after
    substitution: |-
        s^\A(.*)\Z^
           my $body = $1;
           # read in .bbl file
           my $bblFile = ${$self}{fileName};
           $bblFile =~ s/\.tex/.bbl/s;
           my $bblBody = q();
           my $openFilePossible = 1;
           open( BBLFILE, $bblFile ) or ( $openFilePossible = 0 );
           if ( $openFilePossible == 1 ) {
              $bblBody = $bblBody.$_  while (<BBLFILE>);
              close(BBLFILE);
           }
           # split the bbl file at bib-key-begin
           my @bibentries = split(/bib-key-begin---/,$bblBody);
           # loop through the bibliography items
           my $index = 0;
           foreach (@bibentries){
                next if ($_ !~ m/---bib-key-end/s);
                $_ =~ s/(.*?)---bib-key-end//s;
                my $bibKey = $1;
                my $bibValue = $_;
                $bibValue =~ s/\R//sg;
                # make the substitution in the .tex file
                #   \cite{<key>} with <value>
                $body =~ s/\\cite\{$bibKey\}/$bibValue/sg;
           }; 
           $body;^sgxe

and now run

latexindent.pl -rr -l myfile.tex

and the final output is

myfile.tex (final output)

% arara: pdflatex
% arara: bibtex
% arara: pdflatex
% arara: pdflatex
\documentclass[a4paper,11pt]{article}


\begin{document}
As first example citation here is Noam Chomsky. Syntactic Structures. Mouton, The Hague, 1957.. 
Here is another example citation William Labov. Sociolinguistic Patterns. University of Pennsylvania Press,  Philadelphia, 1972.

\bibliographystyle{plain-plain}
\bibliography{\jobname.bib}

\end{document}

final comment

If you need myfile.bbl to contain bold/italics, then you'll have to tweak plain-plain.bst.

You must log in to answer this question.

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