Consistent Latex units in non italics

| categories: latex | View Comments

Yet another latex tidbit. Its purpose - remove italics from the units inside math mode.

in the header :

1: \newcommand{\unit}[1]{\ensuremath{\, \mathrm{#1}}}

in the body :

1: $\tau=0.0257\left[\unit{N\cdot m^{-2}}\right]$

If you want to take this approach to the very extreme, you could have the units of every var defined in the header :

1: \newcommand{\tauunit}{\unit{N}\cdot\unit{m}^{-2}}

And use them consistently without silly unit mistakes inside your manuscript :

1: $\tau=0.4\tauunit$

Copyright (C) 2015 by Avi Gozolchiani. See the License for information about copying.

org-mode source

Read and Post Comments

latex automatic rotation

| categories: latex | View Comments

The usual workflow with a latex document is latex->bibtex->latex->dvips->ps2pdf. There are some variations, on this theme. Anyway - when you use ps2pdf it tries to optimize space and sometimes rotates the figures. There's a whole story about how dvi includes figures as links to files and how dvips,ps2pdf plant this file inside the document. Bottom line is - we don't like automatic orientation of figures. Once we got it right, we want it to behave the same even if the document has changed.

So… to disable automatic rotation in ps2pdf (the source for this tip is over here ):

1: ps2pdf -dAutoRotatePages=/None

Copyright (C) 2015 by Avi Gozolchiani. See the License for information about copying.

org-mode source

Read and Post Comments

LaTeX - please don't mix bibliography and figures

| categories: latex | View Comments

The weird mingling of figs and bibliography which is the default setting in LaTeX could be avoided by using the package "placeins" . You could use several more barriers to make sure that all figures will not leak beyond certain position in text (for example - the end of a section).

1: \usepackage{placeins} % in the header
2: ....
3: \FloatBarrier % this forces all figures to be presented before the bibl.
4: \bibliographystyle{unsrt}
5: \bibliography{gyre_ref} % your bibtex file is probably named differently

Copyright (C) 2015 by Avi Gozolchiani. See the License for information about copying.

org-mode source

Read and Post Comments

create a document from your figures

| 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.

org-mode source

Read and Post Comments