Understanding living systems
Please see more tips in the TeXnical Notes.
1e15 * sum([-10, 1e-15, 10])
?
If you gave answer = 1, put the above expression in MATLAB. You will get
approximately 1.78. So, it is almost an error of 80%. To avoid that possible
blunder for ill-conditioned vectors, always sort you data by absolute value
in a descending order before computing a sum. For example,
1e15 * sum([-10, 10, 1e-15])
gives you unity as expected.
Another instructive example is
if ( 12345678901234567^3 + 2^3 == 12345678901234568^3 )
disp('be careful with floating-point arithmetic')
end
Configure Window Behaviour...
.
Then Window-Specific Settings -> [New...] -> [Detect]
. Click on any MATLAB window,
tick "Whole window class"
. Finally [Geometry] -> Desktop -> Force -> Desktop 5
.
E.g., my settings are
(Default) Disable focus stealing prevention for MATLAB Windows class;
sun-awt-x11-xframepeer com-mathworks-util-postvminit [exact match]
[Geometry] -> Desktop -> Force , 5
[Workarounds] -> Allows focus stealing prevention
-------------------------------- DISTRIBUTED MULTI-CORE COMPUTING --------------------------------For MATLAB newer than 7.8.* (2009), the multithreading (using more than one CPU core) is set up automatically. To check the number of processor cores available in a PC/server, use
feature('NumCores')
Note, that this is an undocumented function (see more details).
And the command
memory
gives you the system memory volume/usage information (MS Windows only).
parfor
from the Parallel Computing Toolbox to split the for
-cycle between
several MATLAB 'workers'. For example, to start a parallel computing session with a
maximum of 2 'working' MATLAB instances (plus one coordinating MATLAB client), use
matlabpool open local 2
...
parfor i = (1 : N)
B(i) = function(A(i))
end
...
matlabpool close
(more info). This is a perfect technique for Monte-Carlo ensemble averages.
See this figure for the performance speed-up on a busy 12-core Intel Xeon cluster ('chiron').
NumWorkers
property.
In the example below, we set the maximum to 12 cores (upper limit in MATLAB) and open a parallel session with 4 'workers'
NUM_CORES = 4;
myCluster = parcluster('local');
myCluster.NumWorkers = 12; saveProfile(myCluster);
matlabpool('open', 'local', NUM_CORES);
---------------------- GRAPHICS AND EXPORTING ----------------------Note that the scaling of an
.eps
-figure depends on the screen resolution you set
before launching Matlab. A running Matlab session will not adjust automatically
when you alter the screen settings. For example, a reduced screen resolution will
give you a figure with a larger bounding box (effectively reducing the font size).
I = getframe(gcf);
imwrite(I.cdata, 'FileName.png');
hh = get(gca, 'Children');
XX = get(hh,'XData'); % or get(hh(1),'XData') if more
YY = get(hh,'YData'); % than one line was plotted
N.B. the first plotted line goes last in hh
.
'Newton''s law'
line('XData',x, 'YData',y, 'LineStyle','none', ...
'Marker','o', 'MarkerSize',7, 'MarkerFaceColor',[0,0,0]);
N.B. x,y
can be vectors to draw a set of points.
hFig = figure('Name','MyFigure');
...
set(0, 'CurrentFigure',hFig); hold on;
figure('Name','Double-Axes Example'); hold on; box on;
XX = 1:0.1:10; YY1=sin(XX); YY2=exp(XX);
plot(XX, YY1, '-k', 'LineWidth',2);
hAx1 = gca;
hAx2 = axes('Position',get(hAx1,'Position'),...
'XAxisLocation','top', 'XTick',[],...
'YAxisLocation','right',...
'Color','none','XColor','k','YColor','k',...
'YScale','log'); hold on;
semilogy(XX, YY2,'--k', 'LineWidth',2, 'Parent',hAx2);
xlabel(hAx1, 'X', 'FontSize',16);
ylabel(hAx1, 'Y1', 'FontSize',16);
ylabel(hAx2, 'Y2', 'FontSize',16);
legend(hAx1, {'a'}, 'FontSize',12, 'Location','NorthWest');
legend(hAx2, {'b'}, 'FontSize',12, 'Color','w');
If you want to be able to click-edit the line properties plotted in the first axes,
add 'HitTest','off'
when creating hAx2.
legend()
use {...}
for captions,
e.g. legend({'caption1','caption2'}, 'FontSize',12);
legend({'line^{index}_1', 'line_2'})
,
which contains subscripts/superscripts, apply
[hL,hLL,auxL,auxT] = legend( ... );
hText = findobj(hLL, 'type','text');
set(hText(end), 'VerticalAlignment','Cap');
where 'Cap'
aligns with the Capital letter (try also 'Top'
).
.eps
figure with a transparent background, use
set(gca, 'Color','none');
set(gcf, 'Color','none');
set(gcf,'InvertHardCopy','off');
print -depsc2 Transparent.eps;
chart('arial'); % prints out character table
pm_char = char(hex2dec('B1')); % \pm char based on its ascii value
mu_char = char(hex2dec('B5')); % \mu char
uicontrol('Style','text', 'String',[pm_char, ' 10 ', mu_char,'m']);
More info.
figure;
hax1 = subplot(2,1, 1);
colormap(hax1, 'jet');
surf(peaks(30)); hc=colorbar;
cbfreeze(hc); % freeze colorbar
freezeColors; % freeze colormap
hax2 = subplot(2,1, 2);
colormap(hax2, 'gray');
surf(10*peaks(100)); colorbar;
Note: cbfreeze
and freezeColors
are unnecessary for MATLAB 8.4 (2014b) or newer,
as long as you specify an axes handle: colormap(h,...)
.
exponent = -2;
set(gca, 'YTickLabel', strtrim(cellstr(num2str(get(gca,'YTick')'/10^exponent))') );
fs = get(gca,'fontsize'); xl = xlim; yl = ylim; set(gca,'units','normalized');
text(xl(1),yl(2), sprintf('\\times10^{%d}',exponent), 'fontsize',0.9*fs, ...
'VerticalAlignment','bottom');
(source: example, and another one)
----------- MISCELLANEA -----------Starting from MATLAB 2010a, a new option
'index0'
will be available for most
of standard array-generating function (zeros(), ones(), diag(), sum()
, etc.)
It forces a so-created array to be indexed from 0 instead of 1. This breaks a nearly
three-decades-long tradition of hard-coded indexing from 1, unlike in the
majority of programming languages. See more details first-handedly.
[Update]: this turned out to be a joke...
'Callback'
-option/value pair is either 'any Matlab code'
or
@mySubFunction_Callback
, the latter WITHOUT quotes (' '). The respective
GUI m-file subfunction is @mySubFunction_Callback(hObj, event, eventdata)
.
clear Variable;
inside the script if the variable under question is global.
It is generally safer to set it to zero. Alternatively, use: clear Variable; global Variable;
(LIST_OF_VARIABLES = {'AnArray', 'ACellArray', 'AScalar'};
for i = [1 : length(LIST_OF_VARIABLES)]
Info = whos(LIST_OF_VARIABLES{i});
if strcmp(Info.class, 'cell')
evalc([LIST_OF_VARIABLES{i}, ' = {}']);
else
evalc([LIST_OF_VARIABLES{i}, ' = []']);
end
end
however, it is not a recommended practice.
Numbers = []; new_number=42;
Strings = {}; new_string='abc';
Numbers = [Numbers, new_number];
Strings = {Strings{:}, new_string};
% or even better
Strings = [Strings; {new_string}];
A( find(A == 3, 1,'last') );
% returns 'ans = 3'
% for A = [1, 2, 3, 3, 3];
3
, use
digits(3); A_sym = sym(A, 'd');
latex(A_sym);
screen
to emulate a terminal session and
matlab -nodisplay
to suppress the graphical support by using the
following command sequence (in a console):
$ ssh username@chiron
$ screen
$ nice matlab -nodisplay -logfile ~/matlablog.txt -r myscript.m
...
press <Ctrl>+a, followed by d
$ logout chiron
To reconnect to the detached screen session, use
$ ssh username@chiron
$ screen -r
and use exit
to close the session.
$ matlab -nojvm -nodisplay < my_script.m
(in Linux / MacOS), or
$ matlab -nojvm -nodisplay -r my_script,quit
(in both Linux and MS Windows).
spy % plots a ... sparse matrix
why(0) % answers any question
sum * % gives the Answer to the Ultimate Question of Life
.mph
or .fl
binary formats;
otherwise, you are at risk of not being able to open your own COMSOL .m
-file.
$ comsol mphserver matlab &
$ comsol &
$ comsol &
from the same terminal (to avoid checking out multiple licences for the same user).
You also need to ensure that the COMSOL configuration file points to the supported
version of the MATLAB (e.g. add a command-line option -mlroot /usr/local/matlab...
or
amend the line in the configuration file: MLROOT=${MLROOT:=/usr/local/matlab...}
).
All Programs -> COMSOL Multiphysics -> License Tools -> LMTOOLS -> Browse ->
C:\Program Files\COMSOL\COMSOL61\Multiphysics\license\license.dat
,
or [in Linux]:
$ cd /usr/local/comsol61/multiphysics/license/glnxa64
$ ./lmstat -a -c ../license.dat
(source).
[in Linux]: $ cd .../comsol61/multiphysics/license/glnxa64/
[in MacOS]: $ cd .../comsol61/multiphysics/license/mac...64/
$ ./lmborrow -status
[in Windows]: > lmutil lmborrow -status
(see more source).
-mesa
to the start-up script (see also
graphics troubleshooting):
comsol35a -mesa &
q0 * u_test
,
where u=u(x,t) is the name of dependent variable in the equation(s). This is
equivalent, in 1D-geometry, to setting the boundary coefficient g = q0
.
In 2D and 3D cases, it is necessary to use Point Settings
of a Point
object and the only weak formulation for the boundary condition is available.
Draw -> Geometric Properties
to make sure all points and lines are precisely at
the positions they should be. An error of order 1e-4
is easily introduced when
drawing manually. A good alternative is to define lines using, e.g.
line1 = solid1([0,1]);
pt1 = point1(0.25); pt2 = point1(0.5);
p.objs = {pt1, pt2}; s.objs = {line1};
fem.draw = struct('p',p,'s',s);
fem.geom = geomcsg(fem);
from MATLAB, or using COMSOL GUI menu option Draw -> Specify Objects
.
And do not forget to regenerate/reload the mesh.
Physics -> Periodic boundaries...
and select the border (edge) that will be a "source" of the boundary data. Note that the
corresponding vertices should also be carefully matched in the correct order.
ellip2()
) and the one with only internal polygons (line2()
) has different indexing
order for the outer borders. For example, if you subtract a polygon and an ellipse
from a rectangular domain ('g_rect2 - g_line2 - g_ellip2'
) and apply type 1 b.c.
on the outer-rectangle, type 2 on the inner-polygon, and type 3 on the inner-ellipse,
the final indexing will be as follows: (1,1,1, 2,2,...,2, 1, 3,3,3,3)
.
Be careful and double-check boundary conditions before computing.
comsol server matlab -compat -c35aroot /usr/local32/comsol35a -mlroot /usr/local/matlab7.10
Study Reference
: just add the component to Study 2 (transport sweep) and make it
refer to Study 1 (flow). Now, running the second study, runs the entire simulation sequence.
The Matlab LiveLink
scripting is also capable of this or more sophisticated automation.
Alternatively, a build-in scripting tool Model Methods
from the Application Builder
could do the job, but it is only available (as of ver. 5.3a) in the Windows distribution.
?plot # for a command
?spatstat::Kest # for a package
??command # generic search
<Ctrl> + L
to clear the console screen.
closeAllConnections()
rm(list=ls())
$ sudo add-apt-repository 'deb http://cran.ma.imperial.ac.uk/bin/linux/ubuntu xenial/'
;
ii. $ sudo apt-get update
;
(if it complains that there is no public key, say, 51716619E084DAB9
)
ii*. $ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 51716619E084DAB9
;
iii. $ sudo apt-get install r-base
> install.packages("Rcmdr")
from within R and wait!).
$ R CMD INSTALL package_name.tar.gz -l $HOME/R-packages/
or
install.packages("package_name", lib="$HOME/R-packages/")
(more info).
source('script.R', echo=TRUE)
within R, or
$R --vanilla < script.R
from the command line.
data <- read.csv("MyDataFile.csv", sep="\t");
library(package="Hmisc")
names(data) # print headers
describe(data$variable1) # summary statistics
...
subset1 <- data[data$var1 == "yes", "var2"] # create a subset
subset2 <- data[data$var2 > 10, "var3"]
...
subset3 = subset(data, select=c(var1, var2, id)) # create a subset with
ind1 = c("var1", "id"); ind2 = c("var2", "id") # both var1 and var2
subset4 = subset( subset3, # for the same id
subset3[ind1]$id == subset3[ind2]$id,
select=c(var1,var2) )
subset5 = na.omit(subset4) # drop NA
...
mean(subset1, na.rm=TRUE) # compute mean, removing 'NA' values
sd(subset1, na.rm=TRUE) # SD
quantiles(subset1, na.rm=TRUE) # Quantiles
...
plot(subset1, subset2, col = "blue") # scatter plot
hist(subset1, col = "blue") # histogram
boxplot(data$var1, data$var2, range=0) # box plot
install.packages(“ggplot2”)
and library(package = "ggplot2")
to access the extensive library of different plotting tools.
expression()
command instead of a string. E.g.
plot( xx, yy, labx="x", laby=expression(y = sqrt(sin(x)^2)), main="..." )
.eps
, use
postscript(file='figure.eps', width=7, height=7, paper="special", horizontal=FALSE)
.
ratio <- (max(Y) - min(Y)) / (max(X) - min(X))
postscript(file="file.eps', width=7, height=7*ratio,
paper="special", horizontal=FALSE)
par(mar = c(2,2,1,1)) # trims the margins (bott,left,top,right)
par(cex = 1.1) # sets font-size-scale 110% of default
plot(X, Y, ..., asp = 1, ann=FALSE )
plot( X, Y, ..., ylim = c(max(Y), min(Y)) )
.
sudo apt-get install xfig gsfonts-x11
.png
or other bitmap image, do not forget to
select 'some smoothing'
or 'more smoothing'
option, otherwise you may
end up with a fuzzy picture. You could also set an optional width of blank border.
Position
property (bottom toolbar) to "any"
or use the Edit
tool to tweak its coordinates arbitrary.
.eps
file is to use the fig2eps utility by Marc de Courville and others
(please note that this is a modified version with an extra option to handle
LaTeX fonts; here is the original fig2eps).
The usage is as follows:
$ $
,
set the font size to affect scaling (8-12 would be fine for labeling diagrams).diagram.fig
, and run from the console:
fig2eps diagram.fig
That's it. The result is a neat figure in the file diagram.eps
, ready to be
inserted to LaTeX.-times
is recommended (run fig2eps -h
for more details).
------------- InkScape Tips -------------To crop an imported image (i) insert a rectangle on top of the desired area (ii)
Object -> clip -> set
(source)
File -> Document Properties -> Background colour
and set Alpha
(opacity) to 255.
.eps
to .png
use
convert -density DPI -resize WIDTH_PIXELSxHEIGHT_PIXELS -rotate ANGLE file_name.eps file_name.png
e.g.
convert -density 150 -resize 1024 file_name.eps file_name.png
Also, an option -sharpen 0xsigma
or -unsharp 0xsigma+amount+threshold
(e.g. -sharpen 0x1
) can be used to reduce a blur, where \sigma is a parameter
of convolution kernel. (source: ImageMagick guru and these notes).
convert file.jpg file.eps
), either specify format explicitly
(convert file.jpg file.eps2
) or force the output format:
convert -density 150 file.jpg eps2:file.eps
You can also try out other raster-to-eps conversion tools, like bmpp or jpeg2ps.
.png
to .eps
, use the following (in Linux command-line):
for f in *.png; do convert -density 300 $f eps2:${f%.*}.eps; done
or
FOR %f IN (*.png) DO convert -density 300 %f eps2:%~nf.eps
(in MS-DOS shell command-line).
img2pdf --output merged.pdf *.png
Alternatively, use a GhostScript-based imagemagick
pipeline:
convert *.png merged.pdf
For example, see attached a custom script screenshot2pdf for cropping, downsampling & converting
a series of PNG screenshots to a PDF.
convert FILENAME -verbose info:-
and also
identify -verbose FILENAME
.eps
figure produced by MATLAB, use
convert figure.eps temp.eps
convert -trim +repage -density 150 temp.eps figure_final.eps
convert -crop +0+50 +repage figure.png figure_cropped.png
see more info and examples.
ps2pdf -dEPSCrop input.eps output.pdf
another useful options to consider: -dPDFSETTINGS=/prepress
(or =/print
)
for a publishing quality optimised output. See GhostScript Documentation for more details.
Alternatively, you could use
epstopdf input.eps
pdf2ps -sDEVICE=epswrite input.pdf output.eps
or
pdftops -eps input.pdf output.eps
The latter is of higher quality but might leave extra white space around the image.
-dUseCIEColor
is an extra option that makes device-independent colours for printing):
# create a .pdf from .eps
ps2pdf -dEPSCrop -dPDFSETTINGS=/printer -dUseCIEColor \
-dCompatibilityLevel=1.3 -dMaxSubsetPct=100 -dSubsetFonts=true \
-dEmbedAllFonts=true figure.eps figure.pdf
# check the fonts
pdffonts figure.pdf
# convert back to .eps
pdftops -eps figure.pdf figure-emb.eps
(sources: Osmanoglu's blog, ps2pdf manual, comp.text.tex group);
batch-convert .eps to .tiff (lossless with 400 dpi and 8-bit colour depth)
for f in *.eps; do convert -density 400 -depth 8 -alpha off -compress LZW $f ${f%.*}.tiff; done.
and add a 2px-wide white border around the images
mogrify -mattecolor white -frame 2x2 *.tiff
(see the figure guidelines).
sudo add-apt-repository ppa:strukturag/libheif
sudo apt install libheif-examples
heif-convert input.HEIC output.jpg
Alernatively (on older Ubuntu 16, 18), download a static build of tifig:
tifig -v -p --width 800 input.HEIC output.jpg
convert -delay 120 -loop 0 *.jpg animated.gif
See more details
ImageMagick
and ffmpeg
:
convert input.gif temp%05d.png
ffmpeg -i temp%05d.png -r 10 -qscale 0 output.avi
rm temp*.png
(here -r
defines the frame rate in Hz, and -qscale
preserves the quality).
Another example that reduces the size of a .GIF:
convert input.gif -scale 50% -fuzz 2% +dither -layers Optimize output.gif
To convert to other formats with ffmpeg
, simply change the extention, e.g. to output.mov
.
For example, the following line converts an .MP4 to an animated .GIF:
ffmpeg -i video.mp4 -vf "crop=720:520:120:0" -f gif video.gif
Note the -vf
option above that crops the original video before converting.
If you do not have ffmpeg
installed, you could do it on Ubuntu with
sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next
sudo apt-get update
sudo apt-get install ffmpeg
source: ffmpeg usage tips, documentation and installation.
JabRef
:
#!/bin/sh
java -jar /PATH_TO_JabRef/JabRef-2.6.jar --import $(readlink -f $1)
then browse and select this script (or just JabRef.exe
itself in MS Windows)
with Open with...
in Firefox each time when you encounter a .ris-file or the like.
N.B. Do not forget to activate Preferences --> Advanced --> Remote Operation
in JabRef.
Scholar Preferences --> Show links to import citations into BibTeX
)Cite/Export --> Export a Citation
)right-click
in the entry editor
and choose the desired format from the menu Change case
.
[LyX/Kile]
button in JabRef:
.lyx
in your home folder;Preferences -> External Programmes
, click on the [LyX]
button,
enter /FULL_PATH_TO_HOME/.lyx/lyxpipe.in
and save.[LyX/Kile]
button and enjoy imported BibTeX keys.
{ }
(to make sure they are preserved in the LaTeX output), go to menu Options -> Preferences ->
General -> File -> "Store the following fields with braces around capital letters"
and include the desired fields, e.g. title;journal;author
.
This setting automatically adds braces when saving the .bib file, but you won't see the
braces within JabRef (from jabref-users mailing-list).
\begin{author}\format[Authors(LastFirst,NoPunc,InitialsNoSpace),HTMLChars,Replace(A Name,<strong>A Name</strong>)]{\author}\end{author}
would print an author list in a compact format with the author "A Name" shown in bold.
Source: JabRef mailing list; see more details.
sudo apt-get install libreoffice-java-common
press Tools --> OpenOffice/LibreOffice Connection
, click on [Manual Connect]
, and set 'path to executable' to
/usr/lib/libreoffice/program/soffice.bin
and 'path to library dir' to /usr/lib/libreoffice
.
pdftk
command-line backend:
PDF Chain (Linux / MacOS), e.g., in Ubuntu
sudo apt-get install pdfchain
and original PDFtk Free/Pro (MS Windows)
pdftk file1.pdf file2.pdf cat output final.pdf
and to glue many sequentially-numbered files, use
pdftk *.pdf cat output final.pdf
See more PDFtk examples.
pdftk file.pdf cat 1east 2-end output fileRotated.pdf
./pdfrotate odd 180 input.pdf output.pdf
(it is based on this script)
Update: the same effect can be achieved by a standard command:
pdftk A=input.pdf shuffle A1-endoddsouth A1-endeven output final.pdf
pdftk A=odd_pages.pdf B=even_pages.pdf shuffle A1-end Bend-1 output final.pdf
pdftk file.pdf output fileFixed.pdf
smpdf
is availabe from the CPDF toolkit:
smpdf input.pdf -o output.pdf
[Update]: for a newer version of cpdf
, use the following syntax instead:
cpdf -squeeze input.pdf -o output.pdf
Another way is to use a lossy GS-based image-compression script shrinkpdf
:
./shrinkpdf input.pdf output-small.pdf
#(use 150 dpi instead of default 72)
./shrinkpdf input.pdf output-small.pdf 150
pdftk in.pdf cat output protected.pdf owner_pw MasterPass user_pw OpenPass
Alternative command for cpdf
(see more CPDF examples):
cpdf -encrypt 128bit MasterPass OpenPass in.pdf -o protected.pdf
To extract some pages from a protected pdf, use
pdftk protected.pdf input_pw MasterPass cat 1 3-end output decrypted.pdf
or, better still:
pdftk protected.pdf cat 1 3-end output decrypted.pdf do_ask
Alternative cpdf
command is
cpdf -merge protected.pdf owner=MasterPass 1,3-end -o decrypted.pdf
Note that when encrypting pdftk
by default revokes all permissions (including printing), while
cpdf
allows printing, copying, etc. unless told otherwise. Also, cpdf
preserves original 'creator'
metadata and produces slightly smaller files, while pdftk
overwrites the metadata with its own.
for f in *.pdf; do pdftk $f cat output ${f%.*}-e.pdf owner_pw MasterPass user_pw OpenPass; done
To decrypt and extract the first page, use
pdftk protected.pdf cat 1 output first_page.pdf do_ask
If no (i.e. empty) user pass is set, one can also use qpdf to decrypt the pdf file:
qpdf --decrypt protected.pdf --password="" out.pdf
Please make sure you have valid authority to process the pdf files.
tiffcp *.tiff OUTPUT.tiff
jpeg
compression)
tiff2pdf -j -o OUTPUT.pdf INPUT.tiff
for f in *.tiff; do convert -compress jpeg -quality 75 $f ${f%.*}.pdf; done
pdftk *.pdf cat output final.pdf
pdftotext
and works only with text-based or OCR PDFs (not image-only scans).
Use the following command:
find . -name '*.pdf' -exec sh -c 'pdftotext "{}" - | grep --with-filename --label="{}" --color "SEARCH STRING"' \;
(See source for more info).
okular
or evince
), use
Master PDF Editor
(free for non-commercial use).
\usepackage{sagetex}
...
\sageplot[angle=30, width=5cm]{plot(sin(x), 0, pi), axes=False}
latexdiff old.tex new.tex > diff.tex
The perl-script latexdiff
doing this is available at CTAN
(sometimes it is necessary to use the script named latexdiff-so
instead).
ps2ascii
utility to a generated .ps or .pdf as follows:
ps2ascii file.pdf | wc
The output consists of three figures. The first one is the number of lines,
the second is the number of words and the last one is the number of
characters (bytes).
hyperref
package warning: Token not allowed in a PDFDocEncoded string...,
provide alternative plain text for maths by using \texorpdfstring{$Your Formula$}{Equivalent Text}
in \section{}
, \subsection{}
, etc. (see also other hyperref problems).
-Ppdf
to dvips
command line (e.g. in Kile/WinEdt settings).
Also, avoid using \usepackage[T1]{fontenc}
but use {\fontencoding{T1}...}
locally instead.
\usepackage[...]{hyperref}
, NOT in the \hypersetup{...}
:
\usepackage[plainpages=false,pdfpagelabels]{hyperref}
More Pdf/LaTeX-related help (see also the UK TeX FAQ and TUG mailist).
minipage
environment with plain-TeX \vss
to make LaTeX ignorant of extra height:
\begin{figure}[p]
\begin{minipage}[t][\textheight]{\textwidth}
\centering \vspace{-1em} % some tweaking
\includegraphics{...}
\vspace{-0.5em} \caption{...} \label{fig:...}
\vss % hides extra height
\end{minipage}
\end{figure}
and do not forget that \label
always go inside or straight after the \caption
.
See more on comp.text.tex.
\usepackage{afterpage}
package, providing a
command \afterpage{ \do_something_after_this_page_ends }
. For example,
to force the queueing floats to be placed as soon as this page ends (without breaking it), put
\afterpage{\clearpage}
or, if you need to have a footnote to a Figure/Table that wrongly appears at the previous page, use
\begin{figure}
...
\caption{Blah-blah-blah \protect\footnotemark .}
\end{figure}
\afterpage{ \footnotetext{Some clarification.} }
Note that this method is NOT very robust, particularly if you try to use the command inside the floats.
Here is the package documentation and some more info on managing the floats.
... e.g.\ we can avoid here an extra space.
See more white space info.
\textstyle
command in the display mode switches fonts and spacing
to be a more compact, e.g.
\textsyle\sum e^{\textstyle a/b}
The other LaTeX maths styles are \displaystyle
, \scriptstyle
and \scriptscriptstyle
.
\usepackage{pst-math,pst-plot,pstricks}
...
\begin{figure}[tp]
\centering
\psset{unit=1.2cm} % use this to scale the picture
\psset{plotpoints=500} % plotting quality (def=50)
\begin{pspicture*}(-0.5,-0.5)(5,3)
% set up axis: (centrx,centry)(minx,miny)(maxx,maxy)
\psaxes[labels=none,ticks=none]{->}(0,0)(0,0)(4.5,2.5)
\rput(4.5,-0.25){ $t$} % label axes
\rput[t](-0.35,2.5){$f(t)$}
% plot f(t) = 2*exp(-5*(t-1)), using Reverse Polish Notation
\psplot[linecolor=blue,linewidth=1.25pt]{1}{3}%
{ 1 neg x add 5 mul neg EXP 2 mul } % x is the argument
% plot a horizontal line and a label
\psline[linecolor=red,linestyle=dashed,linewidth=0.75pt]%
(0,1.5)(4,1.5) \rput(-0.25,1.4){\small$\frac{a}{b}$}
% plot a vertical line
\psset{linecolor=blue,linewidth=1pt,linestyle=dotted}
\psline(2,0)(2,2) \rput(2,-0.25){\scriptsize$\tau$}
\end{pspicture*}
\caption{PSTricks-graph}\label{fig:pstricks-graph}
\end{figure}
c/d + b*exp(-a*x) = x a neg mul EXP b mul c d div add
See The List of PostScript Maths commands, plus extra commands, like EXP
, from the package pst-math.
Alternatively, use package pstricks-add, which provides an option
\psset{algebraic=true}
but the package is sensitive to the LaTeX distribution and prone to instabilities.
\string~
' tip to handle tildes in the url correctly).
iconv -f cp1251 -t utf-8 input.txt -o output.txt
or, in a loop, to re-encode all files
find . -name '*' | while read i; do iconv -f WINDOWS-1251 -t UTF-8 "$i" >tmp; mv tmp "$i"; done
To convert the filenames only, use the convmv utility by Bjoern Jacke:
convmv -r -f WINDOWS-1251 -t UTF-8 ./*
A quick diagnostic summary could also be given by
find . | perl -ane '{ if(m/[[:^ascii:]]/) { print } }' > Non-ASCII-filenames.txt
$HOME/.i18n
and put the following line in it:
LC_COLLATE=C
(b) in Debian/Ubuntu, add the following to $HOME/.profile
file:
export LC_COLLATE=C
then relogin or reboot the PC. (source: CentOS, Arch, Ubuntu).
wine
virtual machine
LC_CTYPE=ru_RU.utf8 wine application.exe
(see more hints).
cal -m 2010
<Shift>
and select desired text by mouse.
cat /proc/cpuinfo
or dmesg | grep CPU
(e.g. cat /proc/cpuinfo | grep processor
tells the number of processors/cores);
check RAM-memory by using cat /proc/meminfo
(in kB) or free -m
(in MB);
check miscellaneous hardware components: cat /etc/sysconfig/hwconf
;
check the disc-space usage & capacity of mounted file-systems: df -h
(add -T
for fs type);
check the number of users in the system finger
;
check the system load by uptime
or top
(the load average numbers show how many of the processor cores are busy).
ifconfig
.
Check wireless network status and properties:
sudo lshw -class network
nmcli connection show
iwconfig wl...
smartctl -a /dev/hda
in Linux (where the required HDD device name can be found via df -h
),
and use a free monitoring tool SpeedFan in MS Windows.
YYYYMMDDhhmm
(e.g. to 2010-03-02, 0:00), use
touch -m -t 201003020000 FILENAME
*.csv
files in one, use
cat *.csv > merged.csv
rename 'old_prefix-' 'new_prefix-' ./*
reformat all the numbers in filenames as 001, 002, ...
./rename.pl 's/([0-9]+)/sprintf("%03d",$1)/e;' ./*
replace all spaces in filenames with '-' (remove 'g' after / to replace only the first occurrence)
./rename.pl 's/\s/-/g' ./*
find and replace ':' with '-' in all filenames for MS Windows compatibility
(a safer version: remove the trailing -n
option after a test run)
find . -name '*:*' -exec rename 's/:/-/g' {} -v -n \;
N.B. It is a good practice to copy the files in a dedicated directory and testing it before running a command.
See also a regex reference and an online regex simulator.
$HOME
directory, use
cd ~
find -regex './\..*' | tar cvfz ./dot_files.tar.gz -T -
or find -regex './\..*' -exec tar zvfc dot_files.tar.gz {} +
more info.
$HOME/BIB_BACKUP/
and
then replace "old string" with "new string" in all matched *.bib-files, use
mkdir $HOME/BIB_BACKUP
find $HOME \( ! -regex '.*/.*reserv.*' \) -iname "*.bib" -exec cp -au {} $HOME/BACKUP \;
find ./ \( ! -regex '.*/.*reserv.*' \) -iname "*.bib" -type f \
-exec grep -q OLDSTRING {} \; \
-exec perl -i.bak -pe "s/OLDSTRING/NEWSTRING/g" {} \; \
-printf "Processed file: %p\n"
N.B. Instead of Perl, one can use -exec sed -ic "s/oldstring/newstring/g" {} \;
as the last operation.
Note that {}
in the -exec
portion is substituted with the found filenames; '\' allows multiline commands,
and '\;' terminates each -exec
statement. Also note that '{' has to be escaped like '\{' in Perl's 'oldstring'.
find ROOT_DIR -iname "FILETYPE" -exec cp {} TARGET_DIR \;
,
e.g. the following moves recursively all mp3-files from current directory to './global_storage/'
find ./ -iname "*.mp3" -exec mv {} ./global_storage/ \;
find $HOME \( ! -regex '.*/\..*' \) -type f -mtime 0
-mtime -n
means during the last n days
find . -xtype l
zip -rTog filename.zip /PATH/*
Note, that you can add -m
to delete these files after archivation.
tar -cvf - DIR | 7z a -si -p DIR.tar.7z
which is an alternative to the standard Unix-like archiving:
tar -cavf DIR.tar.xz DIR/ #create .xz (use .gz for gzip)
tar -xvf DIR.tar.xz #extract .xz
Alternatively, without preserving the ownership, and encrypring the file listing header:
7z a -mhe=on -p DIR.7z DIR
You could also create a less well-compressed zip
-file, using
7z a -p DIR.zip DIR
(Note that an appropriate way to exract files is "7z x FILE
").
wget http://www.midnight-commander.org/downloads/mc-4.6.1.tar.gz
tar -xzvf mc-4.6.1.tar.gz
cd mc-4.6.1
./configure --silent --prefix=$HOME/.mc
(here --prefix
says where to install, subject to your rights to do so,
and --silent
suppresses the auxiliary output)make
make install
bin/
directory (in this case you can
run it as $HOME/.mc/bin/mc
). However obvious it may sound, it is better to have
all bits and bobs of a standard procedure ready at hand.
./synch_dir PATH_TO_DIR
, where
PATH_TO_DIR
is the root path to the directory tree to be synchronised
and synch_dir is the following shell script
#!/bin/sh
# run for every child directory of $1
find $1 -type d | while read path; do
# get the latest modified file in the tree $path
fname=$(find "$path" -type f -printf "%T+\t%p\n" | sort -n | tail -1 | cut -f2);
# set the modif. date of $path to match the attribute of $fname
touch -m -c -r "$fname" "$path";
done
(based on tip 1, tip 2 and tip 3)
chmod -R u=rwX,g=rX,o=rX ./*
chmod +t ./SHARED
sudo ./photorec_static
sudo ./testdisk_static
Note that PhotoRec
seems more straightforward and reliable on FAT32 USB stick-like media.
See more details on using the PhotoRec and TestDisk.
diff --side-by-side File1 File2
(a more advanced alternative is to use IDE like Eclipse
).
settings -> edit profile -> appearance -> black on white
). Alternatively, use
gnome-terminal with edit -> profile preferences -> colours -> pallete -> Linux console
.
ii. download and use Terminus font.
iii. see more mc colour theme options.
sudo apt-get update
sudo apt-get install PACKAGE_NAME # for installing from a repository
sudo dpkg -i PACKAGE_FILE.deb # for a downloaded file
resolve missing dependencies
sudo apt-get install -f
search for a package by its partial name or a name of the file it contains
apt-cache search PACKAGE_NAME
apt-file search .so-FILE_NAME
completely remove a package with its configuration files
sudo apt-get remove --purge PACKAGE_NAME
general clean-up
sudo apt-get autoremove
sudo apt-get autoclean
delete old Linux kernels
sudo apt-get remove --purge $(dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d')
# test
symlinks -rst ~/disk/*
# run
symlinks -rsc ~/disk/*
gnome-session-properties
(e.g. with Alt + F2
) and select
Options --> Automatically remember running applications...
Note however that this could lead to some instability.
~/.local/share/applications/mimeapps.list
.
MyApp.desktop
in ~/.local/share/applications/
with the following content:
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/PATH_TO_APP/MyApp.sh %f
Name=MyApp
Icon=/PATH_TO_APP/MyApp-icon.png
To permanently associate file-type with an App, right-click on it and then select
properties -> open with -> set as default
. (see also .desktop format specification)
gconf-editor
, then go to
apps -> metacity -> global_keybindings
and afterwards to keybinding_commands
.
Note, that in Gnome 2 MATE, you need to run dconf-editor
and find
org -> mate -> marco -> global_keybindings
respectively.
General dconf manipulations:
dconf dump / | grep keyword :: search dconf for an entry
dconf reset -f /org/matel/panel/objects/object-n/ :: delete phantom object n
gsettings set org.gnome.nautilus.preferences sort-directories-first true
gsettings set org.gtk.Settings.FileChooser sort-directories-first true
(similar effect can be done via GUI dconf
editor; source).
Shell link
,
where you enter server hostname (e.g. 'granby'), or the full path to the remote machine.
ssh -X
):
i. Install Win X-server, e.g. XMing
ii. Install PuTTy
iii. Setup PuTTy -> Connection -> SSH -> X11-> Enable
iv. Use $ xfe
as simple GUI, or $ mc
as text-style, file-manager (install sudo apt install xfe
on the target Linux server, if necessary)
source
nohup
:
$ ssh username@remote-server
$ nohup my_command > my_command.log 2>&1 &
$ exit
which outputs 'my_command' stdin and stderr to 'my_command.log'. An alternative is to use disown
:
$ my_command > my_command.log 2>&1 & # script or GUI
$ disown -a && exit
(see this reference more details).
However, a still better and more flexible way is to use a virtual terminal such as screen
:
see an example of using screen
to detach/re-attach a remotely running Malab script.
More details and short-cuts for screen
: quickref.me/screen.
about:config
in the address field and set
browser.preferences.inContent = false
browser.preferences.instantApply = false
about:config -> New -> String -> plugin.disable_full_page_plugin_for_types = application/pdf
about:config -> browser.urlbar.matchOnlyTyped = False
about:config -> New -> Boolean -> extensions.checkCompatibility.3.6 = False
(where 3.6
is the first two numbers of Firefox's version).
A better way, however, is to install a Compatibility Reporter that does this automatically for you.
about:config -> xpinstall.signatures.required = False
firefox -ProfileManager
(or firefox -P
) and then hitting the [Create Profile...]
button
firefox -no-remote
to run a new firefox instance rather than opening another window to existing process.
Edit -> Preferences -> General -> Config Editor
and change the following property
mail.tabs.autoHide = true
source
.emailStar {display: none}
to the /chrome/userChrome.rss
which has to be put in the user profile (e.g. ~/.thunderbird/***.default/
in Linux).
File -> Inspect Chrome Document -> 'Inbox... Thunderbird'
#document/window/menuPopUp(mailContext)
to configure right-click menu)hidden="true"
to the right-hand-side 'Attributes' panelextensions.alwaysUnpack
to true
in the Settings->Advanced->Config Editor)
and then follow the instructions.
panacea.dat
from the main Thunderbird profile directory (source).