linewidth = 2;
fontsize = 16;
fig = gcf;
h = findall(fig, 'Type', 'Text');
set(h, 'FontSize', fontsize)
h = findall(fig, 'Type', 'Axes');
set(h, 'FontSize', fontsize)
h = findall(fig, 'Type', 'Line');
set(h, 'LineWidth', linewidth)
Friday, 1 February 2008
Change Matlab-figures for print
If you use Matlab to generate EPS-files for inclusion in LaTeX-documents, you'll soon find that lines are too thin and text is too small. I use the following script to increase thickness and size in the current figure in Matlab:
Source code in LaTeX
If you want to include source code in LaTeX, you can of course use the standard verbatim environment. There are however many advantages to refer to the actual source file on disk instead of copying its contents into your LaTeX document. Referring to a file on disk can be achieved by using the moreverb package.
I use the following commands:
I use the following commands:
\usepackage{moreverb}\def\verbatimtabsize{4\relax}
to include the package and to set the amount of white space for tab characters to 4 (default is 8). Next define \newcommand{\listscript}[1]{{\textbf{#1}\footnotesize\verbatimtabinput{#1}}}
to have a new command for including e.g. Matlab scripts. Use it as\listscript{cp19.m} to have the file cp19.m in your document.
Thursday, 1 November 2007
Passwordless ssh
It is very convenient to use ssh to login into different workstations or for instance our Beowulf cluster elegast without having to re-type your password all the time. It is possible to setup things in such a way that this is possible. Here's the howto.
First you need to generate a so-called RSA key. Type
This will create two files: id_rsa and id_rsa.pub. The first should be kept secret, the second is public. You should now login into the remote machine. If the file ~/.ssh/authorized_keys exists, append the contents from the file id_rsa.pub to it. If it does not exist, create the directory ~/.ssh (with permissions rwx for yourself and no permissions for group and others) and the file authorized_keys (with permissions rw- for yourself and r-- for group and others) with as its contents the file id_rsa.pub.
You should now be able to do passwordless ssh logins.
First you need to generate a so-called RSA key. Type
ssh-keygen -t rsa
This will create two files: id_rsa and id_rsa.pub. The first should be kept secret, the second is public. You should now login into the remote machine. If the file ~/.ssh/authorized_keys exists, append the contents from the file id_rsa.pub to it. If it does not exist, create the directory ~/.ssh (with permissions rwx for yourself and no permissions for group and others) and the file authorized_keys (with permissions rw- for yourself and r-- for group and others) with as its contents the file id_rsa.pub.
You should now be able to do passwordless ssh logins.
Bash programming
The standard shell under Linux is called Bash (the GNU Bourne Again SHell). Even though people are generally used to do a lot of stuff using graphical user interfaces, the command prompt can be very convenient for some tasks. Here are a few simple examples of how to get things done using your keyboard rather than your mouse.
Command line use by example
To convert all .gif files in a directory to .jpg, type
To find all .tex files in a directory including the subdirectories, type
To filter out those files that contain the word "dimension", use
The code between the backquotes (`) is evaluated first and the output it generated is listed as if you typed it at the end of the command. In Bash you can also use $(command) as an alternative to the backquotes, which has the benefit that it can be nested. For example to get the number of bytes of all tex-files that contain the word dimension, you can say
To make the search on "dimension" case insensitive, use
To count the number of occurences, use
which might be written shorter - but less illustrative - as
I'm sure you can use these examples to do powerful text searches yourself.
To rename a bunch of .gif files in a directory to new names like 001.gif, 002.gif etc., you could type
This example also shows how to use if statements. A simple for loop can be programmed as
Writing scripts
If you have many commands that you use more than once, you can also create a text file in your favourite editor, type #!/bin/bash as the first line, and then put some shell commands. If you save the file and make it executable with chmod (see below), you have written a shell script and can simply execute all command by typing the script's name. This is like creating a Matlab script versus typing commands in the Matlab command window. In bash scripts, you can use a couple of funny looking variable names that have special meaning:
The difference between $* and $@ is subtle. Usually the latter does what you think it will do, while the first one has a slightly different semantic meaning. If you say "$*" it will expand to the single string "$1$IFS$2$IFS$3...", where IFS is an environment variable that contains a space by default but might have another value, e.g. the character ':'. When you say "$@" it will expand to the list of strings "$1" "$2" "$3"..., which is usually what you mean.
Command line use by example
To convert all .gif files in a directory to .jpg, type
for file in *.gif; do convert ${file} ${file%gif}png; doneTo find all .tex files in a directory including the subdirectories, type
find . -name "*.tex"
To filter out those files that contain the word "dimension", use
grep dimension `find . -name "*.tex"`
The code between the backquotes (`) is evaluated first and the output it generated is listed as if you typed it at the end of the command. In Bash you can also use $(command) as an alternative to the backquotes, which has the benefit that it can be nested. For example to get the number of bytes of all tex-files that contain the word dimension, you can say
du -s -k $(grep -l dimension $(find . -name "*.tex"))
To make the search on "dimension" case insensitive, use
grep -i dimension `find . -name "*.tex"`
To count the number of occurences, use
grep -i dimension `find . -name "*.tex"` | wc -l
which might be written shorter - but less illustrative - as
grep -c -i dimension `find . -name "*.tex"`
I'm sure you can use these examples to do powerful text searches yourself.
To rename a bunch of .gif files in a directory to new names like 001.gif, 002.gif etc., you could type
l=1
for f in *.gif; do
mv $f $(printf '%03d' $l).gif
l=$((l+1))
done
This example also shows how to use if statements. A simple for loop can be programmed as
for (( n = 1 ; n < 9 ; n++ )); do echo $n; done
Writing scripts
If you have many commands that you use more than once, you can also create a text file in your favourite editor, type #!/bin/bash as the first line, and then put some shell commands. If you save the file and make it executable with chmod (see below), you have written a shell script and can simply execute all command by typing the script's name. This is like creating a Matlab script versus typing commands in the Matlab command window. In bash scripts, you can use a couple of funny looking variable names that have special meaning:
| Variable | Meaning |
| $0 | name of the script |
| $# | number of arguments given on the command-line when calling the script |
| $1 | first argument given to the script |
| $* | all arguments |
| $@ | all arguments |
| $$ | PID of the script |
The difference between $* and $@ is subtle. Usually the latter does what you think it will do, while the first one has a slightly different semantic meaning. If you say "$*" it will expand to the single string "$1$IFS$2$IFS$3...", where IFS is an environment variable that contains a space by default but might have another value, e.g. the character ':'. When you say "$@" it will expand to the list of strings "$1" "$2" "$3"..., which is usually what you mean.
Parentheses in mathematical formulas
If you use \left( and \right) in LaTeX, it will automatically scale the parentheses for you to match the size of whatever you put between them. Sometimes LaTeX doesn't do a good job though, and you'll have to help the program. Here's an overview of the commands you can use for creating parentheses in different sizes:
- (, )
- bigl(, bigr)
- Bigl(, Bigr)
- biggl(, biggr)
- Biggl(, Biggr)
Wednesday, 31 October 2007
Font sizes in LaTeX
To write text in different sizes in LaTeX, you can use the following standard size-changing commands (from p. 170 in The LaTeX Companion):
- \tiny
- \scriptsize
- \footnotesize
- \small
- \normalsize
- \large
- \Large
- \LARGE
- \huge
- \Huge
Tuesday, 23 October 2007
Source code in LaTeX
If you want to include some source code into a LaTeX-document, you can of course use the verbatim environment. It can be useful to refer to an external file rather than copy & paste the source into the LaTeX-file.
To refer to an external file (which has the advantage that you do not need to apply modifications in two places) can be done by using the moreverb package: insert
You can now use
To refer to an external file (which has the advantage that you do not need to apply modifications in two places) can be done by using the moreverb package: insert
\usepackage{moreverb}at the beginning of your document. I use the following macro
\newcommand{\listscript}[1]{{\footnotesize\verbatiminput{#1}}}
You can now use
\listscript{ex5.m}in your document if you want to include the source text in the file ex5.m.
Subscribe to:
Posts (Atom)