2010年5月27日 星期四

verbatim in beamer

作者: hantis (呢呢是豬) 看板: Hantis
標題: [隨寫] Note: verbatim in beamer
時間: Thu May 27 10:47:12 2010


   In beamer, if one tries to use verbatim in some slide, simply

   \begin{frame} --> \begin{frame}[containsverbatim]

   Otherwise error when compiling.

2010年5月26日 星期三

\href to open a local target

作者: hantis (呢呢是豬) 看板: Hantis
標題: [隨寫] Note: \href
時間: Wed May 26 13:58:29 2010


   \href{URL}{showing text}

   URL can be http something

   and a local target as well, like D:/temp.pdf.

   The file name can be a problem.

   If the target is in the same folder, simply

   \href{temp.pdf}{Open the file.}

   somehow 點超連結之後 原來的檔會被關掉

   可以按 alt + shift + <- 以檢視前一文件

   (如此 acrobat 保持只開著一個文件)

2010年4月16日 星期五

MATLAB colormap

作者: hantis (呢呢是豬) 看板: Hantis
標題: [隨寫] Note: MATLAB colormap
時間: Fri Apr 16 09:15:47 2010


   contourf 之類的 color shading 圖
   有兩個東西會混淆: colormap, caxis

   colormap 是給定一個顏色矩陣
   讓作圖的時候依據data的值是多少來填色
   所以 hot, gray, hsv, winter, autumn, ...
   這些其實是產生顏色矩陣的函數
   例如有個顏色矩陣產生函數叫做 cmatrix
   其色調是從黑色到白色
   那麼

   colormap cmatrix

   作用等同於

   colormapt(cmatrix(128))

   cmatrix(128)所產生的東西是 [R,G,B]
   其中 R,G,B 三個 element 都是從 0 到 1 的 column matrix
   也就是 linspace(0,1,128)'

   所以想使用任意色調來著色
   只需自行產生色調矩陣
   然後放進 colormap 即可

   例如最高值是藍色 [0 0 1]
   最低值是白色 [1 1 1] 的色調
   可以用
   cmatrix = [linspace(1,0,Nc);linspace(1,0,Nc);ones(1,Nc)]';
   colormap(cmatrix)
   這樣就行了
   其中 Nc 是想要分割出來的色段數
   MATLAB內定值是 128

   至於 caxis
   是定義了 colormap 之後
   自行調整 data 中哪個數字視為 colormap 的最高值或最低值
   MATLAB內定是把 data 中的最高值
   以 colormap 的最下面一個顏色來填
   而 data 中的最低值則以第一個顏色來填
   例如上面的 cmatrix
   第一個顏色是白色 [1 1 1]
   最後一個顏色是藍色 [0 0 1]
   假如 contourf 的 Z data 是
   [1 2 3 4;
    5 6 7 8;
    9 8 7 6;
    5 4 3 2]
   那麼在 9 對應到的位置就會填上藍色
   在 1 的地方會填上白色

   假如希望3以下的都用白色來填
   7以上的都用藍色來填
   則可以
   caxis([3 7])
   也就是說
   沒下這道命令的話內定值是 caxis([1 9])
   或者說是 caxis([min(min(Z)),max(max(Z))])

2010年4月8日 星期四

amscd

作者: hantis (呢呢是豬) 看板: Hantis
標題: [隨寫] Note: amscd
時間: Thu Apr  8 11:54:55 2010


   This is an extremely useful package for communative diagrams,
   such as

      after 10 years
   A ----------------> B

   The above example can be obtained by

   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   ...
   \usepackage{amscd}
   ...

   \[
   \begin{CD}
   A @>\text{after 10 years}>> B
   \end{CD}
   \]
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

   Note that the CD environment must be inside the math mode.
   So \begin{align*}\begin{CD} XXX \end{CD}\end{align*} is ok,
   and so is $\begin{CD} XXX \end{CD}$.

2010年4月1日 星期四

jpg for latex

作者: hantis (呢呢是豬) 看板: Hantis
標題: [隨寫] Note: jpg for latex
時間: Thu Apr  1 09:50:22 2010

This note was written long time ago but I didn't post on my board.
Here it goes:
==================================================================
bmeps是將點陣圖如jpg png等
轉成eps或ps圖的driver
直接在黑黑的DOS視窗執行就可以
例如:
bmeps XXX.jpg XXX.ps
就可以把XXX.jpg轉出一張XXX.ps
接著就可以用熟悉的方法來插入圖
然後latex -> dvips -> ps2pdf
不會有問題

不過這個轉圖法會是黑白的
要轉出彩色的則多下個 -c

bmeps -c XXX.jpg XXX.ps
這樣的ps圖就是彩色的
只是這樣的ps圖好像會很大
爛爛的解析度就會到1MB以上

另外一個方法更好
在吳聰穎、吳聰慧的書有提
不過不是很完全
這個方法
可以用\includegraphics{XXX.jpg}直接來
直接執行latex的話會掛掉
因為它需要bounding box
所以要用這個方法的話
得先bmeps -b XXX.jpg XXX.bb
這樣就會generate出XXX.bb這個宣告bounding box的檔
(其實這個bounding box也可以直接下
例如\includegraphics[bb=0 0 300 400,width=5cm,...]{XXX.jpg}
可是這個方法好像不太好)
有了bb檔之後
還要在PREAMBLE下
\DeclareGraphicsRule{.jpg}{eps}{.bb}{}
這樣
latex就OK

這樣子compile出來的dvi是OK的
但是直接dvips會把彩色圖弄成黑白的
這時候要再多下-I c
dvips這個driver有很多option
其指令格式是dvips [option] filename
其中[option]可以有很多
有一個網站有summarize
總之
dvips -I c filename
即可把filename.dvi成功轉成彩色的filename.ps
當然啦
如果本來就沒有jpg圖檔
直接dvips filename是沒有問題的

小結:
欲放入jpg之點陣圖檔最好的方法
1) PREAMBLE放入這行指令
\DeclareGraphicsRule{.jpg}{eps}{.bb}{}
2) 插入圖:
\includegraphics[...]{XXX.jpg}
3) 在Command Prompt製造XXX.bb的bounding box檔:
bmeps -b XXX.jpg XXX.bb
4) 開始compile以及轉檔:
latex main
dvips -I c main
ps2pdf main.ps

要在beamer的title page放圖的指令:
\titlegraphic{...}
例如
\titlegraphic{\includegraphics[width=2cm]{XXX.jpg}}
放在maketitle之前都可以
這個指令會自動把圖放在正下方
如果要放左下角 可以在\includegraphics之前加個\flushleft
當然 \flushright就到右下角
如果要放兩個 一左一右
可以\flushleft \includegraphics[...]{...} \hfill \flushright
\includegraphics...

無法解決的問題:
通常把這行\titlegraphic指令插在\date之前
但是swp55總是會自動把它移到\maketitle之後
以致於圖會不見
所以目前只能在投影片確定好之好
要真正generate講稿的時候
用WinEdt 或是記事本
強制把那行指令移過去對的地方
然後再latex

2010年3月23日 星期二

boxing equations

作者: hantis (呢呢是豬) 看板: Hantis
標題: [隨寫] Note: boxing equations
時間: Tue Mar 23 12:11:12 2010


   With amsmath package, there is one simple command to box a
   displayed equation: \boxed. Here is an example:

   \begin{equation} % equation, align, ... all work
   \boxed{f = ma}
   \end{equation}

   The above will give a boxed equation like

     __________
    |                       |
    |     f = ma       |       (1)
    |__________|

   However, whenever multiple lines are involved, this does not work.
   The empheq package is helpful here. This package is compatible with
   many commonly used packages such as amsmath and fancybox.

   Simplest usage is like

   \begin{empheq}[box=\fbox]{align}
   f & = ma \\
   p & = mv
   \end{empheq}

   These will give something like
    _______
   |                 |
   |   f = ma   |     (1)
   |   p = mv  |     (2)
   |_______|

   There are other types of boxes that can be called within the help
   of fancybox package. They are doublebox, ovalbox, and shadowbox.
   The last one may cause problem and needs some advanced modification.
   For the other two, one can just, for example,

   \begin{empheq}[box=\doublebox]{align}
   ....
   \end{empheq}

   ovalbox actually sucks. So ignore it.

2010年3月18日 星期四

\itemize in pspicture

作者: hantis (呢呢是豬) 看板: Hantis
標題: [隨寫] Note: \itemize in pspicture
時間: Thu Mar 18 11:44:17 2010


   Within pspicture environment, \itemize has to be wrapped within \parbox
   (or some others). For example,

   ...
   \pspicture(0,0)(8,8){
   ...
   \rput[l](1,2){\parbox{5cm}{\begin{itemize}%
   \item This is a test%
   \end{itemize}}%
   ...
   \endpspicture
   ...

2010年3月3日 星期三

eps file output by pstricks

作者: hantis (呢呢是豬) 看板: Hantis
標題: [隨寫] Note: eps file output by latex
時間: Wed Mar  3 11:02:38 2010


   pstricks and other extending packages provide
   great ps figures, but the output is tricky.

   The summary is:
   =========================
   \documentclass{article}
   \usepackage{pstricks}
   ...
   \pagestyle{empty}

   ...
   \fcolorbox{white}{white}{
   \pspicture(x1,y1)(x2,y2)
   ...
   \endpspicture
   }
   =========================
   (Better one figure one file.)
   compile commands:

   latex fig
   dvips fig ----> this allows a quick preview
   when done, then
   dvips fig -E -o fig.eps

   The file has to be (or not?) an eps file.

2010年2月18日 星期四

PostScript math commands

作者: hantis (呢呢是豬) 看板: Hantis
標題: [隨寫] Note: PostScript Math Commands
時間: Thu Feb 18 01:31:07 2010

http://www.ugrad.math.ubc.ca/Flat/math-ref.html