July 31, 2009

For more information about using LyX and Sweave in Windows machines...

Check out the updated instruction by Murat Yildizoglu here: http://yildizoglu.blogspot.com/2009/02/lyx-and-sweave-under-windows-xp.html
And a wonderful paper "Using Swave with Lyx" by Gregor Gorjanc is worth reading, too: http://gregor.gorjanc.googlepages.com/lyx-sweave


LyX and Sweave

I am dreaming if someday I have enough time to write a Chinese text book about how to use R to replace SPSS in processing survey datasets. I am dreaming this book is done with LyX and the R codes in the book are well incorporated into the book. Then I thought about Sweave, a tool that I heard about when I was in  graduate school.

After some  hours of reviewing concepts about shell and online materials about Sweave, I am writing down the steps for setting up the LyX-Sweave environment in a Linux (Fedora 11) machine:

A good guidance of installation and example Lyx files provided by Paul Johnson are available here: http://wiki.lyx.org/LyX/LyxWithRThroughSweave. Below is a bit updated information about the steps.

1. Create a file named Rweave in /usr/local/bin, where two lines of codes are put into the file:
#!/bin/sh
echo "library(\"utils\"); Sweave(\"$1\")" | R --no-save --no-restore


2. Put Noweb.sty and Sweave.sty in /usr/share/texmf/tex/latex/noweb (create the folder "noweb" if necessary). Noweb.sty can be downloaded here and Sweave.sty is available in your R library: /usr/share/R/texmf/Sweave.sty.

3. In the terminal, change to the root, type "texhash" to update the tex system. Then go to LyX, Tools -> Reconfigure. Next, restart LyX.

4. In LyX, Tools->Preferences-->File Handling, choose "Noweb" in "From format" and "LaTeX(pdflatex)" in "To format". Then, in converter box, type "Rweave $$i". Hit Add and Save.

5. Then you can try to open the example files and making the pdf files.

April 03, 2009

Note for installing Traditional Chinese in Lyx (1.6.2)

I recently updated my Lyx to 1.6.2 (released on March 15, 2009)
My operation system is Linux-Fedora Core 10, but I chose to compile the source code rather than using rpm
because the default coding scheming of rpm uses simplified Chinese font "song," which caused errors
when I use for traditional Chinese fonts like uming and ukai.

so, here are the steps for the installation.

1. download, compile and install lyx-1.6.2.tar.gz (note: you should have both qt and qt-devel packages to pass the configuration_

2. download and install texlive packages (use "yum")

3. download and install CJK package (cjk-4.8.2.tar.gz). Extract the file to the directory /usr/share/texmf/tex/latex/cjk.

4. download and install CJK unifornts (including AR PL UMing and AR PL Uaki).
RPM packages are also available (try cjkunifonts-ukai and cjkunifonts-uming).
These packages give you ttc files. But this ttc or ttf files are not what Lyx recognizes. Lyx need to find tmf files. (See Paul Johnson's notes).

5. transforming the ttc files into tfm files (the most difficult part in this process).
If you read Chinese, read this guide. Below is just a brief modification of the note.

5.1  install the package "fontforge"
5.2 download and extract this package font.tar.bz2 to your local folder, say, ~/font.
5.3 copy your ttc font files to ~/font.
5.4 transform the file from uming.ttc to tfm files (this took me about 4 hours):
time fontforge -script subfonts.pe uming.ttc uming Unicode.sfd
5.5 in the folder of ~/font, create a file called "makemap" with these lines in it.
for i in *.tfm
do
cat >> uming.map << EOF
${i%.tfm} ${i%.tfm} < ${i%.tfm}.pfb
EOF
done
5.6 make this file excutable
chmod +x makemap
5.7. do:
./makemap
5.8 create another file called c70uming.fd
% This is c70song.fd for CJK package.
% created by Edward G.J. Lee
% modify by Frank Liu
\ProvidesFile{c70uming.fd}
\DeclareFontFamily{C70}{uming}{\hyphenchar \font\m@ne}
\DeclareFontShape{C70}{uming}{m}{n}{<-> CJK * uming}{}
\DeclareFontShape{C70}{uming}{bx}{n}{<-> CJKb * uming}{\CJKbold}
\endinput
5.9 create the following directories for newly created files:
mkdir -p ~/.texlive2007/texmf-var/fonts/map/dvips/CJK
mkdir -p ~/.texlive2007/texmf-var/fonts/tfm/CJK/uming
mkdir -p ~/.texlive2007/texmf-var/fonts/type1/CJK/uming
mkdir -p ~
/.texlive2007/texmf-var/tex/latex/CJK/UTF8
5.10 copy the files in ~/fonts into specified paths:
cp ~/font/uming.map ~/.texlive2007/texmf-var/fonts/map/dvips/CJK
cp ~/font/*.tfm ~/.texlive2007/texmf-var/fonts/tfm/CJK/uming
cp ~/font/*.pfb ~/.texlive2007/texmf-var/fonts/type1/CJK/uming
cp ~/font/c70uming.fd ~/.texlive2007/texmf-var/tex/latex/CJK/UTF8
5.11 do:
sudo texhash
updmap --enable Map ukai.map

6. follow the above procedule and install another font "ukai" (note, in step 5 replace "uming" with "ukai")

7. Start LyX and run Tools/Reconfigure

8. Restart Lyx and make two environmental settings:
8.1 In Document/Settings/Language, change the language to Chinese (traditional) and change encoding to Unicode CJK (utf8).
8.2 In the Document/Settings/Fonts panel, type "uming" or "ukai" in the CJK box.

Then you should be able to create Chinese documents with Lyx.