2

I like to benefit from my existing myarticles.bib file to create a different report automatically something like in following picture (I prepared this template with tikz).

What is it best way to do it?

enter image description here

  • Have you tried biblatex with the reading style? – Andrew Swann Nov 25 '14 at 8:42
  • biblatex, particularly combined with biber, provides more flexibility and options than traditional bibtex. – Andrew Swann Nov 26 '14 at 9:59
  • I did not look before, I checked after your warning, it is really quick solution however I want more flexibility and options. Thanks @AndrewSwann. I am updating my question regarding the direction I get on after few suggestion I get – trblnc Nov 26 '14 at 10:06
  • biber can make my life easier. Actually this takes me to beginning of my questions before I posted here. bibtex, biblatex or any other package have their own way to access a *.bib file. I just need hack them to give me the data to put in my template. I need to read more biber. – trblnc Nov 26 '14 at 10:13
2

I walked around my question with the following steps. It is not a clear tex solution, may be not suppose to be here, but in any way it is working.

I tried to use with perltex, got some interesting errors.

My Solution

Preparation

I prepare a perl script,

  • to find desired reference and information belongs to that one,
  • parsed into a variables,
  • and create bibREF.tex file which includes my tikz template.

Inside Latex

And I make it run inside latex passing the following steps;

  1. I invoke the perl script manually for each reference I want to see with \immediate\write18{./perl.pl test2013 > scriptoutput.tex}
  2. I call the bibREF.tex with \input \input{bibREF}
  3. go Step 3-4 for each time I want to put a new reference

MWE

\documentclass[12pt]{report}
\usepackage{hyperref}  %nice to have for link,url, cross-references etc.   
\usepackage{xcolor}    %brings the colors
\usepackage[mode=buildnew]{standalone} %magical package to call standalone document class, ignoring their preamble    
\usepackage[a4paper]{geometry}  %margin tricks
\usepackage{tikz}
\usetikzlibrary{backgrounds,calc,positioning}
\thispagestyle{empty}

\begin{document}

\newgeometry{left=2cm,bottom=1.5cm,top=1.5cm}
  \centering
  \immediate\write18{./perl.pl test2013 > scriptoutput.tex}
  \input{bibREF}
  % \restoregeometry

  % \newgeometry{left=2cm,bottom=1.5cm,top=1.5cm}
  \centering
  \immediate\write18{./perl.pl Wang2013 > scriptoutput.tex}
  \input{bibREF}
\restoregeometry

\end{document}

Perl Script

(it is really bad, I started using perl 24hours ago)

#!/usr/bin/perl 
#
# Strict and warnings are recommended.
use strict;
use warnings;
  no warnings "uninitialized";  # Don't warn about unitialized variables#
use Term::ANSIColor; #Some fun
# use 5.010;

# print colored ['bold blue'], "Hey I am a Perl,\n";
# print "I can find all the informations you need for a specific reference from regular";
# print colored ['bold blue'], " bibtex ";
# print "file\n";


my $in = 0;                                                  #logical to check am I in a good line or not
my $refPattern='Wang2013';                                   #which reference I am trying to read
# my $refPattern='test2013'; 
# my $refPattern='',"$_[0]",'';                                   #which reference I am trying to read
my $filename = 'article.bib';                                #bibtex file storing informations

foreach (@ARGV) {
    $refPattern = $_;
};

# print "My variable $refPattern\n";


#possible to improve with list or hash, find them with forearch etc. (did not work yet)
my $abstract  ;                                  #lesson:perl scope has crazy/sensible way
my $author    ;                                  #lesson:perl scope has crazy/sensible way
my $doi       ;                                  #lesson:perl scope has crazy/sensible way
my $issn      ;                                  #lesson:perl scope has crazy/sensible way
my $journal   ;                                  #lesson:perl scope has crazy/sensible way
my $keywords  ;                                  #lesson:perl scope has crazy/sensible way
my $localfile ;                                  #lesson:perl scope has crazy/sensible way
my $note      ;                                  #lesson:perl scope has crazy/sensible way
my $number    ;                                  #lesson:perl scope has crazy/sensible way
my $pages     ;                                  #lesson:perl scope has crazy/sensible way
my $title     ;                                  #lesson:perl scope has crazy/sensible way
my $url       ;                                  #lesson:perl scope has crazy/sensible way
my $volume    ;                                  #lesson:perl scope has crazy/sensible way
my $year      ;                                  #lesson:perl scope has crazy/sensible way
# my %hash = ( 'abstract','author','journal','keywords','localfile','note','title','url');

my $line;                                        #raw line
my $field;                                       #field name
my $content_temp;                                #raw content, without trims
my $content   ;                                  #content for all fields, with trims


open(my $bibfile, '<:encoding(UTF-8)', $filename)
  or die "Could not open file '$filename' $!";

while (<$bibfile>) {                                         #remember perl default variable is in use, $_
    $in = 1 if /$refPattern/i;
    last if (/^$/ && $in == 1);                              #break the while on the first following empty line after $refPattern
    if ($in == 1) {
      $line = $_ if($in);
      $field = substr($line, 1, index($line, ' = '));        #it finds bibtex vartype
      $field =~ s/^\s+|\s+$//g;                       #trim both ends, may be not necessary, do not know how to check if there are spaces around the $field
      print "$field\n";
      $line =~ s/^\s*\S+\s*//;                               #split field and content, field is the first word always
      $content_temp = $line; 
      $content_temp =~ s/^\s+|\s+$//g;                       #trim both ends
      $content_temp =~ s/^\s*\S+\s*//;                       #like split field and content, to delete = on the beginning
      $content_temp =~ s/,\z//;                              #trim last character "," if exist
      next if (length($content_temp) < 1);                   #Check if you really read something
      $content = substr($content_temp, 1, -1);               #If you know the first and last character are quotes, use it, no need to regec



#       print "$content\n";
      $abstract  = $content if ($field eq 'abstract');
      $author    = $content if ($field eq 'author');
      $doi       = $content if ($field eq 'doi');
      $issn      = $content if ($field eq 'issn');
      $journal   = $content if ($field eq 'journal');
      $keywords  = $content if ($field eq 'keywords');
      $localfile = $content if ($field eq 'localfile');
      $note      = $content if ($field eq 'note');
      $number    = $content if ($field eq 'number');
      $pages     = $content if ($field eq 'pages');
      $title     = $content if ($field eq 'title');
      $url       = $content if ($field eq 'url');
      $volume    = $content if ($field eq 'volume');
      $year      = $content if ($field eq 'year');           
#       print "$title\n";
    }                          
}

# print "$journal\n";
# print "$content\n";
# print "$title\n";

my $filename = 'bibREF.tex';
open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
print $fh '%HEYY This is generated by perl.pl, do not touch it, if you need changes go to mother file!!!                                                                             ',"\n";                                                                                                                                   
print $fh '\documentclass[12pt]{standalone}                                                                                                                                          ',"\n";
print $fh '\usepackage{amsmath}                                                                                                                                                      ',"\n";
print $fh '\usepackage{amssymb}                                                                                                                                                      ',"\n";
print $fh '\usepackage{tikz}                                                                                                                                                         ',"\n";
print $fh '\usepackage{gnuplot-lua-tikz}                                                                                                                                             ',"\n";
print $fh '\usepackage[shell]{gnuplottex}                                                                                                                                            ',"\n";
print $fh '\usepackage[]{tcolorbox}                                                                                                                                                  ',"\n";
print $fh '\usetikzlibrary{backgrounds,calc,positioning}                                                                                                                             ',"\n";
print $fh '\thispagestyle{empty}                                                                                                                                                     ',"\n";
print $fh '                                                                                                                                                                          ',"\n";
print $fh '\begin{document}                                                                                                                                                          ',"\n";
print $fh '                                                                                                                                                                          ',"\n";
print $fh '\begin{tikzpicture}[inner sep=0pt]                                                                                                                                        ',"\n";
print $fh '% block/.style={draw,fill=white,rectangle, minimum width={width("Magnetometer")+2pt},font=\small},                                                                        ',"\n";
print $fh '% blockl/.style={draw,fill=white,rectangle, minimum width={400pt},font=\large}]                                                                                           ',"\n";
print $fh '\tikzstyle{styBIBR}  = [draw,fill=black!60,minimum height={30pt},rectangle,text width=5.5cm   ,text centered,font=\bf,text=white,font=\huge];                             ',"\n";
print $fh '\tikzstyle{styYEAR}  = [draw,fill=blue!60,minimum height={20pt},rectangle,text width=5.5cm   ,text centered,font=\bf,text=white];                                         ',"\n";
print $fh '\tikzstyle{styTITLE}  = [draw,,rectangle,minimum height={60pt},text width=11.5cm,                            ,font=\bf, font=\Large];                                     ',"\n";
print $fh '\tikzstyle{styATHR}  = [draw,,rectangle,minimum height={30pt},text width=17cm,                            , font=\large];                                                 ',"\n";
print $fh '\tikzstyle{styJRNL}  = [draw,,minimum height={30pt},rectangle                       ,text width=5.5cm   ,text centered,text=black,font=\small];                           ',"\n";
print $fh '\tikzstyle{styKWRD}  = [draw,rectangle,minimum height={30pt},text width=17cm,                            ,font=\bf, font=\small];                                         ',"\n";
print $fh '\tikzstyle{styLCLF}  = [draw,rectangle,minimum height={10pt},text width=17cm,                             text=blue, font=\footnotesize];  %local file                    ',"\n";
print $fh '\tikzstyle{styURL}  = [draw,fill=blue!20,rectangle,minimum height={20pt},text width=11.5cm,                            ,font=\bf, font=\Large];  %local file              ',"\n";
print $fh '\tikzstyle{styNOTES} = [draw,rectangle,minimum height={436pt},text width=17cm,];                                                                                          ',"\n";
print $fh '\tikzstyle{styTODO} = [draw,rectangle,minimum height={110pt},text width=17cm];                                                                                            ',"\n";
print $fh '\tikzstyle{styCTD} = [draw,rectangle,minimum height={90pt},text width=8.5cm];                                                                                             ',"\n";
print $fh '\draw [draw,use as bounding box] (0cm,0cm) rectangle (17cm, 27cm);                                                                                                        ',"\n";
print $fh '                                                                                                                                                                          ',"\n";
print $fh '                                                                                                                                                                          ',"\n";
print $fh '                                                                                                                                                                          ',"\n";
print $fh '%%%%%%%%%%%%%%%                                                                                                                                                           ',"\n";
print $fh '%top group                                                                                                                                                                ',"\n";
print $fh '%%%%%%%%%%%%%%%                                                                                                                                                           ',"\n";
print $fh '  \node[styTITLE,left=0pt of current bounding box.north west, ,anchor=north west](nodeTITLE) {',"$title",'};                                                              ',"\n";
print $fh '  \node[styATHR,left=0pt of nodeTITLE.south west, anchor=north west](nodeATHR) {',"$refPattern",'};                                                                       ',"\n";
print $fh '  \node[styKWRD,left=0pt of nodeATHR.south, anchor=north](nodeKWRD) {Keywords: ',"$author",'};                                                                            ',"\n";
print $fh '  \node[styBIBR,left=0pt of nodeTITLE.north east, anchor=north west] (nodeBIBR) {',"$refPattern",'};                                                                      ',"\n";
print $fh '\node[styJRNL,left=0pt of nodeBIBR.south, anchor=north] (nodeJRNL) {',"$journal",'};                                                                                      ',"\n";
print $fh '                                                                                                                                                                          ',"\n";
print $fh '                                                                                                                                                                          ',"\n";
print $fh '%%%%%%%%%%%%%%%                                                                                                                                                           ',"\n";
print $fh '%bottom group                                                                                                                                                             ',"\n";
print $fh '%%%%%%%%%%%%%%%                                                                                                                                                           ',"\n";
print $fh '%local file link                                                                                                                                                          ',"\n";
print $fh '\node[styLCLF,left=0pt of current bounding box.south west,anchor=south west](nodeLCLF) {localfile link: ',"$refPattern",'};                                               ',"\n";
print $fh '\node[styCTD,left=0pt of nodeLCLF.north west,anchor=south west](nodeCTD) {\textbf{Cited:} ',"$refPattern",' };                                                            ',"\n";
print $fh '\node[styCTD,left=0pt of nodeLCLF.north east,anchor=south east](nodeCTDBY) {\textbf{Cited by:} ',"$refPattern",'};                                                        ',"\n";
print $fh '\node[styTODO,left=0pt of nodeCTD.north west,anchor=south west](nodeCTD) {\textbf{TODO:} ',"$refPattern",' };                                                             ',"\n";
print $fh '                                                                                                                                                                          ',"\n";
print $fh '%%%%%%%%%%%%%%%                                                                                                                                                           ',"\n";
print $fh '%mid group                                                                                                                                                                ',"\n";
print $fh '%%%%%%%%%%%%%%%                                                                                                                                                           ',"\n";
print $fh ' \node[styNOTES,below=0.pt of nodeKWRD](NOTES) {NOTES:};                                                                                                                  ',"\n";
print $fh '                                                                                                                                                                          ',"\n";
print $fh '\end{tikzpicture}                                                                                                                                                         ',"\n";
print $fh '                                                                                                                                                                          ',"\n";
print $fh '\end{document}                                                                                                                                                            ',"\n";

close $fh;                                                                                                                                    
print "done\n";

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.