create a document from your figures
January 07, 2015 at 08:42 PM | categories: latex, workflow | View Comments
A part of the scientific workflow is creating images and categorizing them into directories. In our little parties, we scientist show these images to each other and brag about our ability to create more. It is therefore very useful to have bundles of these in pdf or html files (depending on the kind of party).
Here's how to create a pdf (using LaTeX) :
1: #!/usr/bin/perl -nw 2: ## syntax : ls fig_patterns | latexfigs.pl > latexfile 3: chomp(); 4: print "\\begin\{figure\}\n\\centering\n\\includegraphics\[scale=1.2,angle=0\]\{$_\}\n"; 5: s/_/\\_/g; 6: print "\\caption\{$_\}\n\\end\{figure\}\n\\clearpage\n";
and Here's how to create a html :
1: #!/usr/bin/perl -nw 2: ## syntax : ls fig_patterns | htmlfigs.pl > htmlfile 3: chomp(); 4: print "<IMG src=\"$_\" width=650><BR>\n"; 5: print "$_<BR><BR>\n";
After some time, you may want to make a section in your book/paper from each directory.
here's the LaTeX version :
1: #!/usr/bin/perl -w 2: ## syntax : anchor_latex.pl "tag" "text" >> file.latex 3: $tag=shift or die "syntax error: anchor_latex.pl \"tag\" \"text\">>file.latex\n"; 4: $text=shift or die "syntax error: anchor_latex.pl \"tag\" \"text\">>file.latex\n"; 5: print "\\section{$text}\\label{sec:$tag}\n";
and here's the html :
1: #!/usr/bin/perl -w 2: ## syntax : anchor_html.pl "tag" "text" >> file.html 3: $tag=shift or die "syntax error: anchor_html.pl \"tag\" \"text\">>file.html\n"; 4: $text=shift or die "syntax error: anchor_html.pl \"tag\" \"text\">>file.html\n"; 5: print "<a id=\"$tag\"><h2>$text</h2></a>\n";
you can include a template for a latexfile in your home directory :
1: \documentclass[A4paper]{article} 2: \usepackage{graphicx} 3: \usepackage{cite} 4: \usepackage{placeins} % floatbarrier definition 5: \usepackage[caption=false]{subfig} 6: \usepackage{fullpage} 7: \newcommand{\unit}[1]{\ensuremath{\, \mathrm{#1}}} 8: \begin{document} 9: TEXT 10: \end{document}
and substitute your created latex code into the TEXT part, using perl again :
1: #!/usr/bin/perl -w 2: # syntax : merge_latex_tmpl.pl tmpfile > merged_file.tex 3: $tmplfilename=$ENV{'LATEXTMPL'}; 4: $filename=shift // die "syntax error"; 5: open TMPL,"<$tmplfilename" // die "could not find the template file"; 6: open FILE,"<$filename" // die "could not find the file $filename"; 7: $uniq_content = join("", <FILE>); 8: while(<TMPL>){ 9: if(/TEXT/){ 10: print $uniq_content; 11: }else{ 12: print; 13: } 14: }
where LATEXTMPL is an environment variable, telling your script the location of your template. I like templates, and I clutter quite a bit as hidden files in my home directory. Do you do it differently ?
Copyright (C) 2015 by Avi Gozolchiani. See the License for information about copying.