Diagrams in scientific publications occasionally link to other elements of the publication, such as bibliographic or section references. Maintaining consistency between the citations in the diagram and the publication can be tricky, but a small Perl script can automate this process.
This can of course work, only if one uses declarative tools for publishing, in my case LaTeX, BibTeX, and Graphviz.
The following Perl script
(download its complete source from here)
reads as its first argument the auxiliary file
generated by LaTeX.
It will then filter its standard input or subsequent arguments replacing
\cite{...}
commands with the labels that LaTeX assigns
to the corresponding entries.
open(IN, $fname = shift @ARGV) || die "Unable to open $fname: $!\n";
while (<IN>) {
$name{$1} = $2 if (/\\bibcite\{([^}]+)\}\{([^}]+)\}/);
}
while(<>) {
while (/\\cite\{([^}]*)\}/) {
$keys = $1;
@keys = split(/\,/, $keys);
undef $names;
for $k (@keys) {
$names .= ',' if (defined($names));
print STDERR "Undefined key [$k]\n" unless (defined($name{$k}));
$names .= $name{$k};
}
s/\\cite\{([^}]*)\}/[$names]/;
}
print;
}
For example, if the input file is
#!/usr/local/bin/dot
#
# $Id: taxonomy.dot,v 1.1 2007/02/03 09:38:54 dds Exp $
#
digraph G {
node [fontname="Helvetica",fontsize=10,shape=box];
edge [arrowhead=none,arrowtail=empty];
cm [label="SQLIA\ncountermeasures"];
cm -> Dynamic;
cm -> Static;
Dynamic -> "Runtime tainting\n\cite{HCF05,XBS06}";
Dynamic -> "Query modification\n\cite{BK04,BWS05,SW06}";
Dynamic -> "Learning\n\cite{LLW02,VMV05} SDriver";
Static -> "Secure coding practices\n\cite{VG01,HL03}";
Static -> "New APIs\n\cite{CR05,MK05}";
Hybrid [label="Hybrid\n\cite{MLL05,HO05,HO06}"];
Static -> Hybrid;
Dynamic -> Hybrid;
Static -> "Analysis\n\cite{WS04,GSD04}";
}
#!/usr/local/bin/dot
#
# $Id: taxonomy.dot,v 1.1 2007/02/03 09:38:54 dds Exp $
#
digraph G {
node [fontname="Helvetica",fontsize=10,shape=box];
edge [arrowhead=none,arrowtail=empty];
cm [label="SQLIA\ncountermeasures"];
cm -> Dynamic;
cm -> Static;
Dynamic -> "Runtime tainting\n[10,26]";
Dynamic -> "Query modification\n[4,5,21]";
Dynamic -> "Learning\n[17,22] SDriver";
Static -> "Secure coding practices\n[23,15]";
Static -> "New APIs\n[7,19]";
Hybrid [label="Hybrid\n[18,12,11]"];
Static -> Hybrid;
Dynamic -> Hybrid;
Static -> "Analysis\n[25,9]";
}
Last modified: Thursday, October 13, 2016 3:40 pm
Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.