TechBlox » Tutorials http://techblox.fusun.ch/wordpress Solutions To A Computer Scientist's Daily Problems Tue, 14 Sep 2010 11:11:54 +0000 en-US hourly 1 http://wordpress.org/?v=3.4.1 Photoshop Alt+Ctr+Shift+E http://techblox.fusun.ch/wordpress/2010/09/photoshop-altctrshifte/ http://techblox.fusun.ch/wordpress/2010/09/photoshop-altctrshifte/#comments Tue, 14 Sep 2010 09:50:09 +0000 TechBloxWriter http://techblox.fusun.ch/wordpress/?p=124 You created many layers and want to apply some effect or adjustment to all of them. What do you do? Ctr+Alt+Shit+E = Magic.

  1. Here I have two layers that need to be pimped.
  2. Hit Ctr+Alt+Shift+E to merge all visible layers into a new one.
  3. Now I can try out some pimping without affecting the original layers. Weehoo.
]]>
http://techblox.fusun.ch/wordpress/2010/09/photoshop-altctrshifte/feed/ 0
Fancy Latex Tables http://techblox.fusun.ch/wordpress/2010/09/fancy-latex-tables/ http://techblox.fusun.ch/wordpress/2010/09/fancy-latex-tables/#comments Mon, 06 Sep 2010 12:47:56 +0000 TechBloxWriter http://techblox.fusun.ch/wordpress/?p=214 Do you like to create funny graphics like the following for your paper?

Masters of Illustrator can probably chop-chop-compose such a thing in a flash. I, however, abruptly failed as I tried to insert formulae. Why not directly script it in latex, I thought. So I unearthed the big old latex manuals and learned about \multicolumn and \cline. Eventually, I came up with the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
\begin{tabular}{|l|c|l|c|l|}
\multicolumn{1}{c}{}
&\multicolumn{2
}{c}{$e_i$}
&\multicolumn{2}{c}{$e_{i+1}$}\\

\multicolumn{1}{c}{$D$}
&\multicolumn{2}{c}{$\overbrace{\hspace{1cm}}^{}$}
&\multicolumn{2}{c}{$\overbrace{\hspace{1cm}}^{}$} \\\cline{1-1}

$P_1$
&\multicolumn{1}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{}   \\\cline{1-1}

$\vdots$
&\multicolumn{1}{c}{}
&\multicolumn{1
}{c}{$W$}
&\multicolumn{1}{c}{}
&\multicolumn{1
}{c}{}   \\\cline{1-1} \cline{3-3}

$P_{i}$
&$\longleftrightarrow$
&$V_0$
&\multicolumn{1}{c}{}
&\multicolumn{1
}{c}{$W$} \\\cline{3-3} \cline{1-1}\cline{5-5}

$P_{i+1}$
&$\longleftrightarrow$
&$V_1$
&$\longleftrightarrow$
&$V_0$ \\\cline{3-3} \cline{1-1} \cline{5-5}

$P_{i+2}$
&$\longleftrightarrow$
&$V_2$
&$\longleftrightarrow$
&$V_1$ \\\cline{3-3} \cline{1-1} \cline{5-5}

$\vdots$
&$\longleftrightarrow$
&$\vdots$
&$\longleftrightarrow$
&$V_2$ \\\cline{3-3} \cline{1-1}\cline{5-5}

$P_{i+k}$
&$\longleftrightarrow$
&$V_k$
&$\longleftrightarrow$
&$\vdots$ \\\cline{3-3} \cline{1-1} \cline{5-5}

$P_{i+k+1}$
& \multicolumn{1}{c}{}
&\multicolumn{1
}{c}{}&
$\longleftrightarrow$
&$V_k$ \\\cline{1-1
} \cline{5-5}

$\vdots$
&\multicolumn{1}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{}   \\\cline{1-1}

$P_m$
&\multicolumn{1}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{}   \\\cline{1-1}

\multicolumn{1}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{}   \\
\end{tabular
}

and

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
\hline
$P_1$

&$\hdots$
&$P_{i}$
&$P_{i+1}$
&$P_{i+2}$
&$\hdots$
&$P_{i+k}$
&$\hdots$
&$P_m$ \\\hline

\multicolumn{1}{c}{}
&\multicolumn{1
}{c}{}
&\multicolumn{1
}{c}{$\updownarrow$}
& \multicolumn{1}{c}{$\updownarrow$}
& \multicolumn{1}{c}{$\updownarrow$}
& \multicolumn{1}{c}{$\hdots$}
& \multicolumn{1}{c}{$\updownarrow$}
& \multicolumn{2}{c}{} \\\cline{3-7}

\multicolumn{1}{c}{}
&
& $V_{0}$

& $V_{1}$
& $V_{2}$
& $\hdots$
& $V_{k}$
& \multicolumn{2}{c}{} \\\cline{3-7}
\end{tabular}

The trick is to create borderless cells using \multicolumn and then fill in horizontal lines with \cline. You’re welcome. Now back to work!

]]>
http://techblox.fusun.ch/wordpress/2010/09/fancy-latex-tables/feed/ 0
Default Latex Template http://techblox.fusun.ch/wordpress/2010/08/default-latex-template/ http://techblox.fusun.ch/wordpress/2010/08/default-latex-template/#comments Mon, 30 Aug 2010 09:42:56 +0000 TechBloxWriter http://techblox.fusun.ch/wordpress/?p=81 I get frustrated every time I install latex and TeXnicCenter and wish to display some formulas or write a short essay and realize that there are no templates whatsoever that I could use. Then I get frustrated even more when I realize that I cannot even remember the most basic latex lines to start a new document. The last time that happened, I decided to add a small template here, so I – and hopefully some other dudes – shall simply copy the code and start a new latex document immediately!

There you go:

1
2
3
4
5
\documentclass[a4paper,12pt]{report}
\usepackage{amsmath,amssymb,amsthm}
\begin{document}
text   
\end{document}

The following template could be employed for a more advanced text, such as a thesis:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
\documentclass[a4paper,twoside,12pt]{scrbook}
\usepackage{amsmath,amssymb,amsthm}
\usepackage[footnotesize,sl,SL,hang,tight]{subfigure}  % helpful package for aligning figures next to each other
\usepackage{longtable} % tables over several pages
\usepackage[font={small,sl},hang,labelfont=bf]{caption} % configure captions
\usepackage{captcont} % continue sufigures over several pages
\usepackage{booktabs} % publication quality tables for LaTeX
%\usepackage{showkeys} % shows the labels above the references for easier development
\usepackage{mathrsfs}
\ifpdfoutput{%
    \usepackage[pdftex]{graphicx}
    \usepackage[]{pdfpages} %for including full pdf pages
}{%
    \usepackage{graphicx}
}
\usepackage{wrapfig} % wraping text around figures
\usepackage{rotating} % rotate figures
\usepackage{verbatim} % multiline comment
\usepackage{algorithmic}
\usepackage[headinclude]{scrpage2} %\KOMAoptions{headinclude}

% Font packages:
\usepackage{times}
\usepackage{helvet}   % sets sans serif font
\usepackage[T1]{fontenc}
%\usepackage{lmodern}

%PDF hyperref config
\ifpdfoutput{%
    \usepackage[pdftex,
        a4paper,
        bookmarks,
    bookmarksopen=true,
    bookmarksnumbered=true,
        pdfauthor={Alfredo Albino},
        pdftitle={My Life And More},
        colorlinks,
        linkcolor=black,
        citecolor=black,
        filecolor=black,
        urlcolor=black,
        anchorcolor=black,
        menucolor=black,
        breaklinks=true,
    pageanchor=true,
        plainpages=false,
        pdfpagelabels=true
]{hyperref}
}{}

\ifpdfoutput{%
    \pdfcompresslevel=9
    \pdfoutput=1
    \DeclareGraphicsExtensions{.pdf,.png}
}{}
\bibliographystyle{alpha
}
\pagestyle{useheadings}

% A4
\topmargin -0.5in
\textheight 9.3in
\textwidth 6.3in
\oddsidemargin 0.18in
\evensidemargin -0.22in
\parskip 0.1in
\parindent 0in

\renewcommand{\arraystretch}{1.5}
\renewcommand{\baselinestretch}{1}

\begin{document}

\begin{titlepage}
    \topmargin 1.0cm
    \oddsidemargin 0.0cm
    \evensidemargin 0.0cm
    %\textwidth 6.5in
    \centering
    \Huge
    \vspace{2.0cm}
    \textbf{\textsf{My Life And More}} \\[1.5cm]
    %\includegraphics*[width=0.4\textwidth]{image} \\[1.5cm]
    \vspace{2.0cm}
    \sffamily
    \Large
    Alfredo Albino
    \\[0.8cm]
    \large
    BEST University
    \\
    August 2010
    \\[1.3cm]
    Prof. Dr. Alfons Aareweg
    \vfill
    %\includegraphics*[width=0.3\textwidth]{logo1} \hfill
    %\includegraphics*[width=0.3\textwidth]{logo2}
    \vspace{3.4cm}
\end{titlepage}
\cleardoublepage


\pagenumbering{roman}
\setcounter{page}{1}


%\include{abstract}
\chapter*{Abstract}
abstract stuff

\cleardoublepage
\cleardoublepage


%\include{acknowledgment}
\chapter*{Acknowledgment}
thanks


\tableofcontents
\cleardoublepage


\pagenumbering{arabic}


\renewcommand*{\chapterformat}{} % show chapter titles only (no numbers)



%\include{chapter1}
\chapter{Start}
\section{Now}
start

\appendix
\clearpage
%\renewcommand*{\chapterpagestyle}{myappendixpagestyle}

\addcontentsline{toc}{chapter}{List of Figures}
\listoffigures
\cleardoublepage

\addcontentsline{toc}{chapter}{List of Tables}
\listoftables
\cleardoublepage

\clearpage
\renewcommand*{\chapterpagestyle}{empty}

%\nocite{*}
\addcontentsline{toc}{chapter}{Bibliography}
%\bibliography{bib}

\end{document}
]]>
http://techblox.fusun.ch/wordpress/2010/08/default-latex-template/feed/ 0
Photoshop – Use Quick Mask Mode! http://techblox.fusun.ch/wordpress/2010/06/photoshop-use-quick-mask-mode/ http://techblox.fusun.ch/wordpress/2010/06/photoshop-use-quick-mask-mode/#comments Mon, 21 Jun 2010 04:00:32 +0000 TechBloxWriter http://techblox.fusun.ch/wordpress/?p=122 Throughout the whole Adobe Creative Suites, masks are among the most important editing tools. In particular, Photoshop provides a quick mask mode, which allows for creating a suitable mask on the current layer fast and comfortably.

We wish to darken the borders of an image in a smooth manner. This can be achieved in probably a hundred thousand ways or more, but I shall present the Quick-Mask-Mode-way.

  1. Select an area using the Marquee Tool (M).

  2. Enter Quick Mask Mode (Q).

  3. To edit the mask you can use any brush, shape, text, filters, etc. Let’s apply a Gaussian blur filter.

  4. Invert the mask (Ctr+I).

  5. Exit Quick Mask Mode (Q).

  6. Edit the masked image to your liking. Open the Levels dialog (Ctr+L) and move the black point slider and the midtone slider up.

Sweet.

Btw: the picture was taken at the Santa Barbara City College.

]]>
http://techblox.fusun.ch/wordpress/2010/06/photoshop-use-quick-mask-mode/feed/ 0
Transfer Sparse Matrix From C++ To Matlab http://techblox.fusun.ch/wordpress/2010/06/sparse-matrix-trick/ http://techblox.fusun.ch/wordpress/2010/06/sparse-matrix-trick/#comments Mon, 14 Jun 2010 04:00:24 +0000 TechBloxWriter http://techblox.fusun.ch/wordpress/?p=121 It happens that your C++ code solves large sparse linear systems that involve large sparse matrices. Debugging such code is a be-yotch. Only super-brained engineers can spot hidden errors in matrices that are displayed as an unformatted array of numbers. And even for them it’s an inconvenient affair. But not to worry. Matlab gladly helps us displaying any matrix in many wonderful ways.

First, we need some mechanism to render the matrix into a file. Let A be a sparse matrix. We open a file file, iterate over all values in A, and write every item sItem with preceding row and column number into a new line:

1
2
3
4
5
6
7
8
9
10
11
12
13
QFile *file = OpenFileWriteOnly("A.txt");
if (file != NULL)
{
    SparseRowMatrix::const_iterator it;
    for (it = A.begin(); it != A.end(); it++)
    {
        QString sItem = QString::number(it.data());
        QString sLine;
        sLine.sprintf("%d %d %s \n", it.row(), it.col(), sItem.toAscii().data());
        file.write(sLine.toAscii());
    }
    CloseFile(file);
}


Second, we load the matrix into matlab using the following code:

1
2
>> tmp = load('A.txt');
>> A = sparse(tmp(:, 1) + 1, tmp(:, 2) + 1, tmp(:, 3));

And third, voilà, you can use your all time favorite matlab methods to analyse the sh*t out of A. If you have no favorite one, try

1
>> spy(A)

Wow, this matrix surely looks odd…

]]>
http://techblox.fusun.ch/wordpress/2010/06/sparse-matrix-trick/feed/ 0
That or Which? http://techblox.fusun.ch/wordpress/2010/06/that-or-which/ http://techblox.fusun.ch/wordpress/2010/06/that-or-which/#comments Tue, 01 Jun 2010 14:20:42 +0000 TechBloxWriter http://techblox.fusun.ch/wordpress/?p=75 Have you ever found yourself lost because you could not decide whether to use “which” or “that” in a sentence? I did! But not anymore!  I would like to present some rules, as found in the book ”The Elements of Style” by Strunk and White.

That” is defining, restrictive, limiting. Use it to specify which one. You cannot split the sentence into two without losing information.

Which” is nonrestrictive, non-defining. Use it to add a fact about the noun to the text. You could split the sentence into two. Note that nonrestrictive relative clauses are parenthetic; comas are therefore needed.

In many sentences either one can be employed, but the sentence’s meaning is changed.

Example A

“The neighbor’s dog, which I killed yesterday, was purple.”

means “The neighbor’s dog was purple. And also I killed the neighbor’s dog yesterday.”

“The neighbor’s dog that I killed yesterday was purple”

means “Yesterday I killed the neighbor’s purple dog.” They have more than one dog and I killed the purple one. It cannot be split into two sentences: “The neighbor’s dog was purple. Yesterday I killed the neighbor’s dog.” In the second sentence, information about which of the neighbor’s dogs I killed is missing.

Example B

We were donated 8 sequences that comprise between  500 and 1500 frames.” Wrong. It can be split into two sentences: “We were donated 8 sequences. The 8 sequences comprise between 500 and 1500 frames.” Furthermore, “comprise between 500 and 1500 frames” does not define which sequences we were donated. One cannot ask:  ”Which 8 sequences?” Answer: “The ones that comprise between 500 and 1500 frames.“ Correct: “We were donated 8 sequences, which comprise between  500 and 1500 frame.

Example C

The set K contains only numbers, which are larger than k“. Wrong, unless the author wanted to say “The set K contains only numbers.” and In the set K, all numbers are larger than k.” “Which are larger than k” is not meant to add a fact about K, but to define K. Correct: “The set K contains only numbers that are larger than k.

This should help careful writers improve their work.

]]>
http://techblox.fusun.ch/wordpress/2010/06/that-or-which/feed/ 0
Illustrator Clipping Masks http://techblox.fusun.ch/wordpress/2010/05/illustrator-clipping-masks/ http://techblox.fusun.ch/wordpress/2010/05/illustrator-clipping-masks/#comments Fri, 28 May 2010 09:30:06 +0000 TechBloxWriter http://techblox.fusun.ch/wordpress/?p=49 Extremely useful. Innumerable applications.

Start with any object; it can be a placed image, text, a line, a shape, anything… For simplicity, I chose a half-circle.



Draw any shape on top of it.

Select both, right click->Make Clipping Mask

Voilàs!

And the good thing is: Both objects remain in the figure. You can still adjust, move around, or delete both objects individually.

]]>
http://techblox.fusun.ch/wordpress/2010/05/illustrator-clipping-masks/feed/ 0
Advanced Formulae in Latex http://techblox.fusun.ch/wordpress/2010/05/advanced-formulae-in-latex/ http://techblox.fusun.ch/wordpress/2010/05/advanced-formulae-in-latex/#comments Thu, 27 May 2010 17:06:39 +0000 TechBloxWriter http://techblox.fusun.ch/wordpress/?p=15 Remember when you couln’t think of the correct commands to write a certain formula in latex because it’s been a year since you did it the last time? This might help you find the light.

Vectors

Using

1
\newcommand{\ve}[1]{\mbox{\bf #1}}

in your preamble, you can easily write vectors as follows:

1
2
3
\begin{equation}
    \mathscr{L}(\ve v_i) = \ve v_i - \frac{1}{\left| N_i \right|} \sum_{j\in N_i} \ve v_j
\end{equation}

Matrices

You always need matrices. Try this code:

1
2
3
4
5
6
7
8
9
10
\begin{equation}
    \begin{pmatrix}
        A & A_k
    \end{pmatrix}
    \begin{pmatrix}
        D \\
        D_k
    \end{pmatrix}
    = 0
\end{equation}

Multi-case definition

This code comes in handy to define certain funtions or matrices:

1
2
3
4
5
6
7
8
\begin{equation}
    A_{ij} = \left\{
        \begin{array}{l l}
            1 & \quad (i,j) \in K \\
            0 & \quad \text{otherwise} \\
        \end{array}
        \right
\end{equation}
]]>
http://techblox.fusun.ch/wordpress/2010/05/advanced-formulae-in-latex/feed/ 2
Latex Fonts in Illustrator http://techblox.fusun.ch/wordpress/2010/05/adobe-illustrator-formulas-and-latex-fonts/ http://techblox.fusun.ch/wordpress/2010/05/adobe-illustrator-formulas-and-latex-fonts/#comments Thu, 27 May 2010 04:18:53 +0000 TechBloxWriter http://techblox.fusun.ch/wordpress/?p=3 I recently wanted do insert a formula into a Adobe Illustrator figure. Since I didn’t find a way to do so directly in Illustrator and copying a formula from MS Word didn’t work properly, I wanted to copy the formula from a latex generated pdf (or ps) file. This, however, didn’t work either, as some latex fonts (CMR8, ect.) were missing. There’s probably a way to include them while generating the pdf file. But the easiest way I found was to copy all type 1 font files from my latex distribution C:\Program Files (x86)\MiKTeX 2.8\fonts\type1\public\amsfonts\cm to the windows font directory C:\Windows\Fonts. That worked. Yay. ]]> http://techblox.fusun.ch/wordpress/2010/05/adobe-illustrator-formulas-and-latex-fonts/feed/ 0