TITLE:LaTeX サポート (LaTeX Support)
原文 = http://ankisrs.net/docs/dev/manual.html#latex
----
目次
#contents
&br;&br;
LaTeX はパワフルな植字システムであり、数学の公式、化学式、音楽記号などの入力に最適です。Anki は LaTeX を部分的にサポートしており、ノートに LaTeX コードの入力が可能です。カードの復習時には、Anki は LaTeX を呼び出し、生成された画像を代わりに表示します。
//LaTeX is a powerful typesetting system, which is ideal for entering mathematical formulas, chemical formulas, musical notation and so on. Anki provides some support for LaTeX, allowing you to enter LaTeX code in your notes. When you review a card, Anki will call LaTeX and display the generated image instead.
* インストールと前提知識 [#installing-and-assumed-knowledge]
//* Installing and Assumed Knowledge
Anki の LaTeX サポートにはややこしい設定が必要です:既にユーザーが LaTeX の使い方を知っており、既にインストール済みであることを前提としています。LaTeX を使った経験がなければ、インターネットで利用可能なたくさんのガイドを参考にしてください。LaTeX マークアップに疑問点などがあれば、LaTeX フォーラムで質問をしてください。
//Anki’s LaTeX support is not turn-key: it is assumed that you know how to use LaTeX already, and that you have it installed. If you have no experience with LaTeX, please consult one of the many guides available on the internet. If you are having trouble with markup, please ask on a LaTeX forum.
LaTeX のインストールをするには、Windows では MiKTeX、OS X では MacTex、Linux では ディストロのパッケージマネージャを使ってください。dvipng もインストールする必要があります。
//To install LaTeX, on Windows use MiKTeX; on OSX use MacTex, and on Linux use your distro’s package manager. Dvipng must also be installed.
>''ノート''
>Windows では、MikTeX のメンテナンスウィンドウで Settings を選び、"Install missing packages on the fly" を "Ask me first" ではなく "No" に設定してください。これでもまだ問題がある場合、全てのパッケージが入手されるまで Anki を管理者権限で起動することで動作させることができたという報告がありました。
//>''Note''
//>On Windows, go to Settings in MikTek’s maintenance window, and make sure "Install missing packages on the fly" is set to "No", not to "Ask me first". If you continue to have difficulties, one user reported that running Anki as an administrator until all the packages were fetched helped.
>''ノート''
>OS X では、LaTeX は MacTex と BasicTex でのみテストされています。BasicTexを利用する場合、以下のコマンドにより dvipng を別にインストールする必要があります:
> sudo tlmgr update --self; sudo tlmgr install dvipng
//>''Note''
//>On OSX, LaTeX has only been tested with MacTex and BasicTex. If you use BasicTex, you need to install dvipng separately, with the following command: tlmgr update --self && tlmgr install dvipng. If you want to install from MacPorts or similar, you will need to figure out any issues yourself.
>コマンドには path が通っていない場合、フルパスを指定する必要がある。例:
> /usr/local/texlive/2014basic/bin/x86_64-darwin/tlmgr.
//>The command may not be on the path, so you may need to provide the full path, eg /usr/local/texlive/2014basic/bin/x86_64-darwin/tlmgr.
>''ノート''
>上記の LaTeX パッケージ以外を使っている場合、"edit LaTeX" アドオンを使い latex と dvipng のフルパスを指定する必要があります。
//>''NOTE''
//>If you are not using the above LaTeX packages, you will need to use the "edit LaTeX" add-on to specify the full path to latex and dvipng.
* Web/Mobile 上での LaTeX [#latex-on-web-or-mobile]
//* LaTeX on Web/Mobile
LaTeX の記入されたカードを復習した際、Anki は LaTeX の画像を生成しコレクションのメディアフォルダーに入れ、将来的に利用できるようにします。Web 上やモバイルクライアントは画像ファイルがあればこれを表示します。ただしこれらのクライアントは画像を生成することはできません。
//When you review a card with LaTeX on it, Anki will generate an image for that LaTeX and place the image in your collection’s media folder for future use. The web & mobile clients will display these images if they already exist, but can not generate the images on their own.
他のクライアントで学習する前に全てのカードを一度は学習しなければならないという事態を避けるため、Anki には画像を一括で生成する機能があります。全ての画像を生成するには、ツール>メディアをチェック (Tools>Check Media) を使用してください。これにより、生成されたメディアが同期時に AnkiWeb と他のクライアントにアップロードされます。
//To avoid having to review all your cards at least once before you can study on the other clients, Anki can generate the images in bulk for you. To generate all the images, please go to Tools>Check Media. After that, syncing should upload the generated media to AnkiWeb and the other clients.
* 使用例 [#example]
//* Example
LaTeX コンテンツを入力する最も一般的な方法は、 [latex][/latex] タグで囲むことです。この文書の [[エディター>2.0/Editing]] セクションに、ショートカットボタンがあります。
//The most general way to input LaTeX content is to surround it with [latex][/latex] tags. There’s a shortcut button for this documented in the [[editor:http://ankisrs.net/docs/manual.html#editor]] section.
例えば、Ankiカードの front に以下のように入力すると:
//For example, entering the following on the front of an Anki flashcard:
Does [latex]\begin{math}\sum_{k = 1}^{\infty}\frac{1}{k}\end{math}[/latex] converge?
(総和 ... は収束するか?)
以下のようなカードとして表示されます:
//will produce this when the flashcard is viewed:
#ref(convergence_question.png)
上の例のような数式は '''テキスト数式 (text formula)''' と呼びます。数式ではないテキストの中に表示されるからです。対照的に、以下の例は '''ディスプレイ数式 (displayed formula)''' です:
//The formula in the example above is called a '''text formula''', because it is displayed right within the non-mathematical text. In contrast, the following example shows a '''displayed formula''':
Does the sum below converge?
(以下の総和は収束するか?)
[latex]\begin{displaymath}\sum_{k = 1}^{\infty}\frac{1}{k}\end{displaymath}[/latex]
#ref(convergence_question_2.png)
'''テキスト数式''' と '''ディスプレイ数式''' は最もよく使われる LaTeX 表現なので、Anki には省略表記があります。
//'''Text formulas''' and '''display formulas''' are the most common type of LaTeX expressions, so Anki provides abbreviated versions of them. Expressions of the form:
[latex]\begin{math}...\end{math}[/latex]
は
//can be shortened to
[$]...[/$]
と略記できます。また、以下の形式
//and expressions of the form
[latex]\begin{displaymath}...\end{displaymath}[/latex]
は
//can be shortened to
[$$]...[/$$]
と略記できます。例えば、前にあげた 2つの LaTeX 式は それぞれ 以下と等価です。
//For example, the two LaTeX snippets shown before are equivalent to
Does [$]\sum_{k = 1}^{\infty}\frac{1}{k}[/$] converge?
と
//and
Does the sum below converge?
[$$]\sum_{k = 1}^{\infty}\frac{1}{k}[/$$]
//respectively.
* LaTeX パッケージ [#latex-packages]
//* LaTeX packages
Anki では LaTeX のプリアンブル (preamble) を変更し、化学用や音楽用などのカスタムパッケージを導入することができます。例えば、インターネット上で chemtex のサンプルファイルを見つけたとします:
//Anki allows you to customize the LaTeX preamble so you can import custom packages for chemistry, music and so on. For example, imagine you find an example file for chemtex on the internet:
\documentclass[a4paper,12pt]{report}
\usepackage{chemtex}
\begin{document}
\initial
\begin{figure}[h]\centering
\parbox{.3\textwidth}{\ethene{H}{H$_3$C}{CH$_3$}{Br}}
\hfil
\parbox{.3\textwidth}{\cbranch{H}{S}{H}{S}{C}{S}{}{S}{H}
\xi=-200 \cright{}{Q}{C}{D}{O}{S}{OH}}
\hfil
\parbox{.3\textwidth}{\hetisix{Q}{Q}{Q}{Q}{Q}{Q}{O}{Q}{O}
\xi=-171 \fuseup{Q}{Q}{Q}{Q}{D}{Q}{D}{Q}{D}}
\caption{Chemie mit {\tt CHEMTEX}\label{a1}}
\end{figure}
\end{document}
まず最初に、パッケージと MiKTeX/MacTex のドキュメントに従い、パッケージをインストールします。パッケージが動作することを確認するため、上記のようなコードを .latex ファイルに書き込み、コマンドラインからコンパイルすることができることを確認します。これを確認したらパッケージは動作可能なので、Anki にパッケージを導入します。
//Firstly, follow the documentation of the package and MiKTeX/MacTex in order to install the package. To check the package is working, you’ll want to put code like the above into a .latex file and test you can compile it from the command line. Once you’ve confirmed that the package is available and working, we can integrate it with Anki.
Anki でパッケージを使うには、メインウィンドウの "Add" ボタンを押し、次にノートタイプ選択ボタンを押してください。"Manage" ボタンを押し、使おうとしているノートタイプを選択して "Options" をクリックします。LaTeX ヘッダーとフッターが表示されます。ヘッダーは以下のようになっています:
//To use the package with Anki, click "Add" in the main window, then click the note type selection button. Click the "Manage" button, then select the note type you plan to use and click "Options". The LaTeX header and footer are shown. The header will look something like:
\documentclass[12pt]{article}
\special{papersize=3in,5in}
\usepackage{amssymb,amsmath}
\pagestyle{empty}
\setlength{\parindent}{0in}
\begin{document}
chemtex を使うには、前述の例に usepackage 行を追加し、このようにします:
//To use chemtex, you’d add the usepackage line in the earlier example, so it looks like:
\documentclass[12pt]{article}
\special{papersize=3in,5in}
\usepackage{amssymb,amsmath}
\usepackage{chemtex}
\pagestyle{empty}
\setlength{\parindent}{0in}
\begin{document}
これにより、Anki カードに以下のような行を含めることができるようになります:
//After that, you should be able to include lines like the following in your Anki cards:
[latex]\ethene{H}{H$_3$C}{CH$_3$}{Br}[/latex]
* LaTeX との競合 [#latex-conflicts]
//* LaTeX Conflicts
LaTeX で数式を記述する際、{{ と }} が現れることは珍しいことではありません。LaTeX の等式が Anki のフィールド置換と競合しないことを確実にするため、セパレータを別のものに変えることができます。
//It's not uncommon for {{ and }} to pop up in LaTeX code when writing mathematical equations. To ensure that your LaTeX equations don't conflict with Anki's field replacements, it's possible to change the separator to something else.
例えば、以下のテンプレートがあるとします:
//For example, if you have a template:
{{latex field}}
これを次のように変えることで LaTeX との競合が起こりにくくなります:
//Changing it to the following will make it unlikely that the LaTeX will conflict:
{{=<% %>=}}
<%latex field%>
この書式は LaTeX ではたいへんよく現れるものの、LaTeX を使う・使わないに関わらず、上記の方法はカードに {{ }} を含める必要があるどんな場合にもうまく動作します。
//While this most commonly occurs with LaTeX, the solution presented here will work in any situation where you need to include {{ }} on cards, regardless of whether LaTeX is used or not.
穴埋め問題を使う場合、穴埋め問題をマークするのに使う二重カッコを変えることはできません。代わりに二重の閉じカッコの間にスペースを入れ、穴埋めの終わりを示さないようにすることができます。よって
//When using cloze deletions, you cannot change the double braces used to mark cloze deletions; instead, you can put a space between any double closing braces that do not indicate the end of the cloze, so
{{c1::[$]\frac{foo}{\frac{bar}{baz}}[/$] blah blah blah.}}
は正しく動作しませんが
//will not work, but
{{c1::[$]\frac{foo}{\frac{bar}{baz} }[/$] blah blah blah.}}
は正しく動作します。(LaTeX の数学モードではスペースを無視し、等式の表示は変わりません。)
//will (and LaTeX ignores spaces in math mode, so your equation will render the same).
* 安全でないコマンド [#unsafe-commands]
//* Unsafe commands
Anki ではカードやテンプレートにおいて、\input や \def といった特定のコマンドを禁止しています。これらを認めると、悪意ある公開された単語帳でシステムに損害を与えることができるためです。(安全を期してこれらのコマンドはコメントでも禁じられており、使った覚えがないのにこのエラーが表示される場合、ヘッダーやテンプレートやカードのコメントを再度チェックしてください。)これらのコマンドを使う必要がある場合、これらをシステムパッケージに追加して、前のセクションで説明してようにインポートしてください。
//Anki prohibits certain commands like \input or \def from being used on cards or in templates, because allowing them could allow malicious shared decks to damage your system. (To be on the safe side, these commands are prohibited even in comments, so if you're getting this error but don't think you've used one, please double-check any comments you have in your headers, templates, and cards.) If you need to use these commands, please add them to a system package and import that package as described in the previous section.