Skip navigation

Category Archives: LaTeX

One significant disadvantage of using LaTeX, especially as a non-native speaker, is lack of grammar checker as in MS Word. Although it was really painful to do grammar check, now it becomes much easier than before, especially thanks to OpenOffice.

Previously, to check grammar, I converted LaTeX document in to a HTML file (by latex2html or latex4ht) and opened it with MS Word.

An annoying part of this procedure is that mathematical equations and variables are not recognized as equation objects. As a result, MS Word thinks that there many grammatical errors and typos. For example, a variable A_{t} is regarded as “at.”

Since OpenOffice employs MathML, a converted document in an OpenOffice format is much more comparable to the original LaTeX document. Even though OpenOffice version 3 or higher is capable of grammar checking, we can use OpenOffice to export the converted document as a .doc file or a .rtf file, so that we can open it with MS Word.

Procedures:

  1. Install TeX4ht if not available
  2. Convert your .tex file by
    mk4ht oolatex your_filename.tex
  3. A .odt file and a bunch of other files will be generated
  4. Open the .odt file by OpenOffice and perform grammar check

 

I was pretty much astonished by the quality of the conversion and how smooth I can check my grammar.

LaTeXではコードを記述することでいろんな図が書けたりする。これまでは、pstricks packageが主流だったけれども、最大の問題点はpdflatexに対応していない点。pdflatexがより使われるようになって、それまでの定番パッケージがずいぶんと変わってきた。プレゼンをするにしても、それまではprosperが主流だったのがbeamerに取って代わられている(ここ最近のjob market talkとかホントにbeamerばっかり)。それと同様に、pstricksはpgf packageに取って代わられるはず。pgfは普通のLaTeXでも動くらしいし。

pgfとTikZ (pgfのfront-end)を使ってみたけど、結構使えると思う。ちなみに、pgfとbeamerは同じ作者によるモノ。余談だけど、この作者はホント面白い。っていうか、かなり親切、というか、おせっかい。普通、LaTeX系のマニュアルは必要最低限のモノしか入っていなかったりするけど、この作者の場合、プレゼンをする時のガイドライン的なモノや、「プレゼントはこうあるべきだ」、「こうすべきではない」的なモノが盛り沢山だったりする。pgfのマニュアル(なんと300ページ以上ある!)でも、論文における図の役割や、効果的な図の使い方、なんかにもふんだんにスペースが割かれている。しかも、「論文を書くにあたって、同じ量の文を書くのと同じだけ、図にも時間を割かなければいけない。多くの人たちは、適当に作った汚い図を論文に入れてる。これはけしからん。」的なコトも書いてあった。あー、あと、「図やグラフで使われているフォントは本文のフォントと同じにすべきだ」なんていうのもあったかも。個人的にはかなり納得するし、同じように考えている訳だけれども、それにしても、これだけ強い意見を持っていると、ずいぶんと変わったヒトだな、っていう印象を受ける。

pstricksを触ったことは無いのでなんとも言えないけど、pgfはかなり重宝しそうな予感。pgf packageでは別にinstallしてあるgnuplot(MacPortsでgnuplotを入れるとAquaTermも入れてくれるけど、更にteTeXまで入れてくるので、teTeXはdeactivateしてuninstallした)を使うことで、parametricなグラフを書くコトが出来る。

いくつかの注意点:

  1. (pdf)LaTeXが外部のプログラムを呼び出すことが出来るようになっていなければいけない。
    --shell-espape--enable-write18オプションをコンパイルするときにつける。
  2. (pdf)LaTeXがgnuplotを見つけることが出来なければいけない。
    gnuplot: command not foundと言われてしまう。
    ボクの環境の場合、
    % which pdflatex
    /usr/local/teTeX/bin/powerpc-apple-darwin-current/pdflatex
    $ which gnuplot
    /opt/local/bin/gnuplot

    だったので、他に方法があるのかもしれないけれども、手っ取り早い方法として
    $ cd /usr/local/teTeX/bin/powerpc-apple-darwin-current/
    $ sudo ln -s /opt/local/bin/gnuplot ./gnuplot

    として、pdflatexと同じディレクトリにgnuplotへのシンボリックリンクを貼っておいた。
  3. pdfsync packageを使わないこと。
    上の二つの問題は解決したものの、どうもキチンと動かなくて悩んでいたんだけど、どうやら、pdfsync packageとの相性が悪いみたい。まぁ、確かに、pgfとgnuplotとの連携のコトを考えれば、pdfsyncが上手く動かないっていうのは、何となく納得できるけど、今まで重宝してきただけに残念。

    ↑これ、ホント重要。自分で書いておきながら、スコっと忘れてて、エラーが出てしまいちょっと悩んだ。

pgfを使って作られたモノ(gnuplotとの連携も含めて)のgalleryはココ

LaTeXのtableの下に注釈をつける。

  1. minipageを使う

    \begin{table}
    \begin{tabularx}{0.9\hsize}{ccc}
    table entries...
    \end{tabularx}
    \begin{minipage}{.88\hsize}
    notes on the table...
    \end{minipage}
    \end{table}
  2. threeparttable packageを使う。\usepackage[flushleft]{threeparttable}とすると、tablenotesのitemがインデントされない。

    \begin{table}
    \begin{threeparttable}
    \begin{tabular}{ccc}
    table entries...
    \end{tabular}
    \begin{tablenotes}
    \item [] note on the table...
    \item [] note on the table...
    \end{tablenotes}
    \end{threeparttable}
    \end{table}

hyperrefとlatexdiffのコンフリクト(特にsectioning)についてlatexdiffの作者にemailしてみた。

基本的には、latexdiffがunderlineやstrike-outの為に使っているuleum packageがコンフリクトを起こす原因っぽい。で、今のところ完全な解決策は無いらしい。

回避する手段としては、

  1. 新規追加を意味する\uwaveと削除を意味する\soutコマンドを削除してしまう。(\ulemを使わなくていいので、コンフリクトが起きないが、モノクロで印刷する場合、どこを変更したか分かりにくくなってしまう)
  2. latexdiffを走らせるときに--exclude-textcmd=section,subsectionというオプションをつけることで、latexdiffがsectionやsubsectionの変更を反映しないようにする。
  3. hyperref packageを使わない。
  4. もしかしたら、hyperref packageの\texorpdfstringを上手く使うことでもう少し一般的な解決方法が得れるかも知れない。
    の4つを教えてくれた。

    以下は作者からの返答の一部

    Problem arises because of incompatibility between hyperref and ulem package (which is used for strike-out and underlining). The ulem commands seem to cause an error, when it is used in something that will be converted to a link (such as a section title). The workaround in this case is to remove \uwave and \sout commands from \DIFdel and \DIFadd definitions (most conveniently using show–preamble and -p option), which means changes are only highlighted in colour. You might also wish to experiment with \texorpdfstring (see hyperref manual) to make it work more generally – let me know how you are getting on, as this might be useful for other users to know.

    Or use –exclude-textcmd=section,subsection to disable markup of section titles but of course, one usually likes these to be marked up. Or disable hyperref package while you are doing markup (would require defining dummy commands to replace specific hyperref commands).

latexdiffは2つの異なったバージョンのLaTeX fileを比較してくれる。CTANに収録されているのは、Perlで書かれているものだけれども、Rubyで書かれているものも存在する(ただし、pdflatexはつかえない)。

CTANにあるものを取ってきて、自分でinstallしようとしてみたけど、なぜだか上手く行かない。Makefileのpathの設定に問題があるような気もするけど、良く分からないので深入りしないことにする。MacPorts (以前までDarwinPortsと呼ばれていたもの)に最新版のlatexdiffが入っていたので、それを使って楽をすることにする。(Finkにも入っているのを確認したけど、どうやらlatexdiffのバージョンは最新版じゃ無いっぽい。そういう面でFinkは使えないと思う。)これでLaTeXでもWordの様に校正の履歴をトラックしたりすることが出来るようになった。

paperを書く上では、LaTeXは欠かせない(っていうか、文献リストだったり、図表の扱いを考えるだけでも、よくWordを使ってpaperを書くなぁ、とすら思う。いまだに多くの人がWordでpapeを書いてるし、LaTeXが取っつきにくいのはよく分かるけど…)。だけど、校正だったりとか文法チェックとかの面で不利な面があったコトは事実で(もちろん、LaTeXにはWordでは考えられないようなメリットがいっぱいあるけど)、少なくとも、これで一つの欠点を補うことが出来た。

追記:
どうやら、latexdiffがgenerateするcommandはhyperref packageを使っていると問題を引き起こすっぽい。具体的には、\sectionや\subsectionに変更が生じた場合、.tex fileをtypesetしたときに、errorが出てしまう。たとえば、latexdiffに含まれているexample filesでlatexdiffした場合、何の問題もなしにきれいに結果が出力されるけれども、(使わないにも関わらず)preambkeに\usepackage{hyperref}を入れるだけで、それまで問題なくtypeset出来ていたモノがerrorを吐くようになってしまう。簡単にこれを回避する方法としては、\sectionを\section*といったように、セクション番号なしにすることで回避できる(でも、スマートな解決方法じゃない)。

追記2:
CTANからsource fileをdownloadして自分でインストールする方法が上手く行かなかった理由は、どうやらSafariにある気がする。CTANにあるfileは.plの拡張子「無し」だけれども、それぞれのfileの先頭に! /usr/bin/perlって書いてあることから、Safariが勝手にPerl scriptと判断して、.plの拡張子をつけていたコトが問題だったっぽい。Makefileをみても、.plは出てこないし、おかしいと思っていたんだけど、結局そういう事だったみたいだ。Firefox等でdownloadするか、Safariでdownloadして拡張子を削るか(Finder上でタダ単に拡張子を削っても拡張子が隠されるだけなので、cmd+iとかTerminal.appで変えないといけない)、Makefileを書き換えるか、いずれかの方法が必要。

確かに、MacPortsでInstallすると、簡単だけどどうやらlatexdiff-soをinstallしているっぽい。PowerBookの方には、自分でlatexdiff-fast(UNIXのdiffコマンドを使うもの)をinstallしてみたけど、非力なPowerBookでも全然早く動いた。

以前として、hyperrefとの相性が悪い問題は解決出来ていない。

Prosper

Download Prosper from http://sourceforge.net/projects/prosper/

Untar the file and put the folder called prosper at ~/Library/texmf/tex/latex/

Typeset via TeXShop:
According to this page, we need to create a personal script since the dvi file from Prosper contains special information, the usual typeset in TeXShop does not work in order to get a pdf file.

However, at least we work with LaTeX (not platex), it seems that we just need to change its typeset option in TeXShop from Pdftex to TeX + Ghostscript in the preference.

Beamer

Although Prosper is really popular for those who prefer to make slides with LaTeX, it is not so appealing to Mac OS X users. It is just because Prosper uses ps files.

Contrary to Prosper, Beamer dicretly works with pdf files. This seems to be more attractive to Mac OS X (and TeXShop) users.

Download Beamer (and also pfg and xcolor) from https://sourceforge.net/projects/latex-beamer/.

Place those components in
~/Library/texmf/tex/latex/beamer
~/Library/texmf/tex/latex/pgf
~/Library/texmf/tex/latex/xcolor
respectively.

On Terminal.app, run

mktexlsr.

colortbl packageを使う。

Example:

\begin{tabular}{l l | r r }
\rowcolor[gray]{0.8}
20 & Primary metal & 0.0046 & 0.0010\\
21 & Fabricated metal & 0.0060 & 0.0070\\
\end{tabular}

colortblexample.png

cellだけに色を塗ることも可能。
詳しくは、
manualを参照。

プリアンブルに

\pagestyle{empty}

と指定する。