Wednesday, August 19, 2015

Imagemagick in bash, resize images

The following command will resize an image to a height of 100:
convert example.png -resize x100 example.png
 Src: http://www.howtogeek.com/109369/how-to-quickly-resize-convert-modify-images-from-the-linux-terminal/

Tuesday, August 4, 2015

Latex Temporarily disable superscript in citation

The following example changes \setcitestyle locally and puts it in macro \citen. \setcitestyle of package natbib (2010/09/13 8.31b) contains a space right at the beginning of the macro definition by an uncommented end of line, the trick with \romannumeral removes this space.
\documentclass{article}
\usepackage[square]{natbib}
\setcitestyle{super}

\newcommand*{\citen}[1]{%
  \begingroup
    \romannumeral-`\x % remove space at the beginning of \setcitestyle
    \setcitestyle{numbers}%
    \cite{#1}%
  \endgroup   
}

\begin{document}
Package \textsf{accsupp}\cite{oberdiek:accsupp}.
This figure is reproduce from reference~\citen{oberdiek:zref}.
\bibliographystyle{plainnat}
\raggedright
\bibliography{oberdiek-bundle}
\end{document}
Result
Inside moving arguments (e.g., \caption) macro \citen can be protected using \protect or by using \DeclareRobustCommand for the definition:
\newcommand*{\citen}{}% generate error, if `\citen` is already in use
\DeclareRobustCommand*{\citen}[1]{%
  \begingroup
    \romannumeral-`\x % remove space at the beginning of \setcitestyle
    \setcitestyle{numbers}%
    \cite{#1}%
  \endgroup
}
 
Source: http://tex.stackexchange.com/questions/94178/temporarily-disable-superscript-in-citation

Friday, July 24, 2015

bash split pdf

$ sudo apt-get update
$ sudo apt-get install pdftk
EDIT: since pdftk became deprecated, do:
sudo snap install pdftk

Then, to make a new pdf with just pages 1, 2, 4, and 5 from the old pdf, do this:

$ pdftk myoldfile.pdf cat 1 2 4 5 output mynewfile.pdf
Note that cat and output are special pdftk keywords. cat specifies the operation to perform on the input file. output signals that what follows is the name of the output pdf file.
You can specify page ranges like this:
$ pdftk myoldfile.pdf cat 1-2 4-5 output mynewfile.pdf 
 
http://linuxcommando.blogspot.ca/2013/02/splitting-up-is-easy-for-pdf-file.html 

Find LaTeX multiply-defined labels

perl -nE 'say $1 if /(\\label[^}]*})/' *.tex | sort | uniq -c | sort -n
 
 http://www.mawode.com/blog/blog/2012/03/21/finding-duplicate-latex-labels/

Thursday, July 9, 2015

MATLAB uniform ticks (uniformticks) and printing

The following script can make the axes nicer. Example:

%% render uniform ticks digits on Y axis
function uniformticks_y(deci) ; % input number of decimals as string
command = ['%0.' mat2str(deci) 'f|'] ;
ticks = get(gca, 'Ytick') ;
set(gca, 'YTickLabel', sprintf(command, ticks));

However, changing the graph manually in the GUI can upset the nice axes settings. Simply rerun the script from the console without closing the graphs.

Monday, June 22, 2015

convert graph image to text data

To convert a screenshot, photo or scan of a graph or plot to a text data table, use this software:

Engauge Digitizer

http://sourceforge.net/projects/digitizer/?source=navbar

bash copy a directory recursively, excluding some directory or file name

rsync -av --progress sourcefolder /destinationfolder --exclude thefilenametoexclude
rsync -av --progress sourcefolder /destinationfolder --exclude thefoldertoexclude
 
NOTE: if the filename or directory appear multiple times, they will be excluded multiple times

Src:http://stackoverflow.com/questions/4585929/how-to-use-cp-command-to-exclude-a-specific-directory