lualatex

2021年5月31日 (月)

vscodeでtexを編集する(lualatex)

2021/5/31
初版

VSCode TeX

VSCode TeX

概要

vscodeでtexを編集する方法について述べる。
Pandoc(+TeX)のインストール方法で述べたインストールが完了している前提とする。
ホスト環境はubuntuを想定する。

プラグインのインスール

VSCodeの以下のプラグインをインストールする:

LaTex Workshop LaTeX language support

LaTeX_Workshopの簡単な説明は「 LaTeX Workshopってなに?どうやって使うの?調べてみた! 」を参照のこと。

プラグイン「LaTex Workshop」の設定

以下のsetting.jsonを編集する:

Windows %APPDATA%\Code\User\settings.json #実際のファイルのロケーションは以下になる: C:\Users\USER\AppData\Roaming\Code\User\setting.json macOS $HOME/Library/Application Support/Code/User/settings.json Linux $HOME/.config/Code/User/settings.json #実際のファイルのロケーションは以下になる: ~/.config/Code/User/Setting.json

具体的には(ubuntuを使用しているので) ~/.config/Code/User/Setting.jsonを編集する。
setting.jsonの後ろに以下を追加する:

<既にあった設定> //LaTeX "latex-workshop.latex.recipes": [ { "name": "lualatex", "tools": [ "lualatex", ] }, { "name": "lualatex twice compile", "tools": [ "lualatex", "lualatex", ] }, ], "latex-workshop.latex.tools": [ { "name": "lualatex", "command": "lualatex", "args": [ "--cmdx", "-file-line-error", "-synctex=1", "-interaction=nonstopmode", "-halt-on-error", "%DOC%", ], }, ], "latex-workshop.latex.autoClean.run": "onBuilt", "latex-workshop.latex.autoBuild.run": "onFileChange", "latex-workshop.latex.autoBuild.interval": 0, "latex-workshop.view.pdf.viewer": "tab", }

・上のようにjson形式を崩さないように追加する

samples

通常のものとlualatexならではのlua言語を利用したものをサンプルとして挙げる。

sample.tex

%\documentclass[a4j,12pt]{jreport} \documentclass[a4j,12pt]{ltjreport} \title{ {\LaTeX} 動作確認テスト・サンプルファイル} \author{情報リテラシTA} \date{\today} \begin{document} \maketitle \chapter{\LaTeX の世界にようこそ!} \section{インストール成功!} \LaTeX の世界にようこそ!この文章が「dviout」というソフトで閲覧できていれば、 インストールに成功しています。 \LaTeX(ラテフ)もしくは\TeX(テフ)は、 組版処理を行うソフトウェアです。 数学者・コンピュータ科学者のドナルド・クヌース氏によって作られました。 このソフトを使うと、きれいな文章の作成ができます。実際に出版の現場でも使われているそうです。 数学者が作ったということもあって、特に数式の出力がきれいにできるのが特徴です。 \begin{eqnarray} & \displaystyle \lim _{x \rightarrow 1} \left( \frac{2}{x-1} - \frac{x+5}{x^3 -1} \right)\; ,\; & \displaystyle \int ^\pi _0 \cos ^2 (x)dx \nonumber \end{eqnarray} 2つの数式が、きちんと表示されていますか? 複雑な数式が入った文章も、きれいに出力することができます。 \section{基本手順} では、\LaTeX で文章を作る際の、基本的な手順をここに示します。 \begin{enumerate} \item ソースファイルをTeraPadなどのエディタで作成する。 ソース(素)となるファイルを作成します。これにはエディタと呼ばれるソフトを使います。 この地点では文章の形にはなっていません。 \item ソースファイルをコンパイルして、dviファイルを作成する。 パソコンに変換を命令して、先ほどつくったソースファイル をdviファイルに変換、文章の形にして確認します。 \item dviファイルができたことを確認したら、PDFに変換する。 dvi形式は、あまり一般的ではありません。 そこで、Adobe Readerなどで閲覧ができるPDF形式に変換します。 \end{enumerate} \end{document}

・lualatex向けに修正してある

neko.tex

%\documentclass[dvipdfmx]{jsarticle} \documentclass{ltjsarticle} \begin{document} 吾輩は猫である。名前はまだ無い。 どこで生れたかとんと見当がつかぬ。 何でも薄暗いじめじめした所で ニャーニャー泣いていた事だけは記憶している。 吾輩はここで始めて人間というものを見た。 \end{document}

・lualatex向けに修正してある

UpperRiemannSum.tex

% Animation for Upper Riemann Sum % Author: Edson Josテゥ Teixeira \documentclass[10pt]{beamer} %%%< \usepackage{verbatim} %%%> \begin{comment} :Title: Animation for Upper Riemann Sum :Tags: Mathematics :Author: Edson Josテゥ Teixeira :Slug: upper-riemann-sum An animation to the area of calculation using the upper Riemann sum. That's an approximation of an integral by a finite sum, named after the German mathematician Riemann. It is calculated by partitioning the region below the the curve into rectangles and summarizing their areas. To get a better approximation, the region is devided more finely. As the rectangles get smaller, the Rieman sum approaches the Riemann integral. This animation shows it. \end{comment} \usepackage[controls]{animate} \usepackage{tikz} \usetikzlibrary{arrows} % Beamer Settings \usetheme{Warsaw} % Counters \newcounter{higher} \setcounter{higher}{1} \begin{document} \begin{frame}[fragile]{Upper Riemann Sum} \begin{figure} \begin{animateinline}[poster = first, controls]{5} \whiledo{\thehigher<30}{ \begin{tikzpicture}[line cap=round, line join=round, >=triangle 45, x=4.0cm, y=1.0cm, scale=1] \draw [->,color=black] (-0.1,0) -- (2.5,0); \foreach \x in {1,2} \draw [shift={(\x,0)}, color=black] (0pt,2pt) -- (0pt,-2pt) node [below] {\footnotesize $\x$}; \draw [color=black] (2.5,0) node [below] {$x$}; \draw [->,color=black] (0,-0.1) -- (0,4.5); \foreach \y in {1,2,3,4} \draw [shift={(0,\y)}, color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$}; \draw [color=black] (0,4.5) node [right] {$y$}; \draw [color=black] (0pt,-10pt) node [left] {\footnotesize $0$}; \draw [domain=0:2.2, line width=1.0pt] plot (\x,{(\x)^2}); \clip(0,-0.5) rectangle (3,5); \draw (2,0) -- (2,4); \foreach \i in {1,...,\thehigher} \draw [fill=black,fill opacity=0.3, smooth,samples=50] ({1+(\i-1)/\thehigher},{(1+(\i)/\thehigher)^2}) --({1+(\i)/\thehigher},{(1+(\i)/\thehigher)^2}) -- ({1+(\i)/\thehigher},0) -- ({1+(\i-1)/\thehigher},0) -- cycle; \end{tikzpicture} % \stepcounter{higher} \ifthenelse{\thehigher<30}{ \newframe }{\end{animateinline} } } \caption{Upper Riemann Sum} \end{figure} \end{frame} \end{document}

totoro.tex

% Totoro sitting in the snow % By Noa Hoffmann and Pascal Gテシnthner, 21.12.2020 \documentclass[tikz,11pt]{{standalone}} %%%< \usepackage{verbatim} %%%> \begin{comment} :Title: Totoro sitting in the snow :Tags: Foreach;Decorations;Pic;To paths;Fractals;Decorative drawings;Fun :Author: Noa Hoffmann;Pascal Gテシnthner :Slug: totoro This is a drawing of Totoro, the star of the Japanese animated fantasy film "My Neighbor Totoro". The Koch snowflake fractal has been used to draw snow, repetitive tasks are done in "foreach" loops. \end{comment} \usepackage{calligra} \usepackage[T1]{fontenc} \usetikzlibrary{% shapes, shadows, patterns, calc, decorations.shapes, decorations.fractals, decorations.markings, decorations.pathmorphing } \colorlet{bodycolor}{black!35!gray!60!brown!98!green} \colorlet{bellycolor}{yellow!70!white!92!green} \tikzset{ furspot/.pic = { \path [draw = black, thick, fill] (0,0) .. controls +(0.3,0) and +(0.25,-0.05) .. ++(0.35,-.45) .. controls +(-0.45,0.25) and +(0.1,0) .. ++(-0.85,-0.05) .. controls +(-0.3,0.1) and +(-0.4, 0) .. cycle; }, claw/.pic = { \path [fill = bodycolor!70, draw] (0,0) arc (0:45:0.2 and 0.8) arc (135:180:0.2 and 0.8) arc (180:360:0.059) -- cycle; }, whiskers/.pic = { \path [fill = bodycolor!70,draw] (0,0) arc (0:45:0.05 and 2.3) arc (135:180:0.3 and 2.3) to[out=-90,in=-90] cycle; }, snowflake/.pic = { \fill [decoration = Koch snowflake, white] decorate{ decorate{ decorate{ (-0.5,-0.3) -- ++(60:1) -- ++(-60:1) -- cycle }}}; \foreach \i in {30, 90, 150, 210, 270, 330} { \draw[blue!50!white,very thin] (0,0) -- +(\i:0.3); } \draw[decoration = Koch snowflake, blue!50!white, very thin] decorate{($(0,0)+(60:0.2)$) -- ($(0,0)+(300:0.2)$) -- ($(0,0)+(180:0.2)$) -- cycle}; } } \tikzset{ snow/.style = {decoration = {random steps, segment length = 2mm, amplitude = 0.4mm}, decorate}, plush/.style = {decoration = {random steps, segment length = 1mm, amplitude = 0.5mm},decorate} } \begin{document} \begin{tikzpicture}[color = bodycolor, draw = black, thick] %---------------------background and tail---------------------- % blue sky \fill[blue!30!white] (-8cm,-11cm) rectangle (8cm,10cm); % random snowflakes \foreach \i in {0.1,0.11,...,1}{ \pic [scale = \i, opacity = 0.9] at (rand*7.5, rnd*18-10.5) {snowflake};} % more tiny snowflakes \foreach \i in {0.1,0.11,...,0.5}{ \pic [scale = \i, opacity = 0.9] at (rand*7.5, rnd*18-10.5) {snowflake};} % cloud with merry christmas \node [cloud,aspect = 6.5, cloud puff arc = 120, cloud puffs = 12.9, fill = white, color = white] at (0,7) {\Huge M \hspace{9.8cm}.}; \node [color = red] at (0,7) {\fontsize{50}{80} \textbf{Merry Christmas \quad }}; % tail \path [draw, fill, rotate = 50] (-4,-7.5) circle (1.5 and 2.2); % snowhill \fill [draw, gray!6, snow] (-8,-11) to[in=200, out=0] (-3,-7.5) to (3,-7.5) to[out=-20, in=180] (8,-11); %--------------------body----------------------------------------- % right ear \path [fill, draw] (0.6,2.3)+(-45:1) arc (-60:35:1 and 1.5) arc (115:210:1 and 1.5); % left ear \path [fill, draw] (-0.6,2.3)+(-135:1) arc (-120:-215:1 and 1.5) arc (65:-30:1 and 1.5); % head \path [draw, fill] ($(0,0)+(170:2.5 and 2)$) arc (170:10:2.5 and 2) arc(35:-20: 3 and 2) -- ($(0,-0.8)+(200:3 and 2)$) arc (200:145:3 and 2) -- cycle; % body \path[fill] ($(0,-4)+(200:4 and 4.5)$) arc (200:-20:4 and 4.5); %----------------------face---------------------------------------- % left eye \path [draw, fill = white] (-1.4,0.7) circle (0.45 and 0.4); \fill [black] (-1.2,0.7) circle (0.16); \fill [white] (-1.24,0.74) circle (0.03); % right eye \path [draw, fill = white, thick] (1.4,0.7) circle (0.4); \fill [black] (1.25,0.7) circle (0.16); \fill [white] (1.20,0.74) circle (0.03); % nose \path [draw] (0.35, 0.7) .. controls (0.2,0.8) and (-0.2, 0.8) .. (-0.35, 0.7); \path [fill = black] (0, 0.53) -- (0.25, 0.6) .. controls (0.3,0.75) and (-0.3, 0.75) .. (-0.25, 0.6) -- cycle; \pic [scale = 0.3] at (0,0.8) {snowflake}; % mouth \draw (-0.05,-0.5) arc (140:85:0.2 and 0.1); % whiskers \foreach \i/\j/\k/\l/\m in {80/1/1.5/-2/0, -90/-1/1.5/-2.2/-0.2, -80/-0.8/1.5/-2.5/-0.5, -80/1/1.3/2.2/0, 90/-1/1.3/2.4/-0.2, 80/-1/1.3/2.6/-0.4} \pic [rotate = \i, scale = \j, yscale = \k] at (\l,\m) {whiskers}; %-----------------------------arms---------------------------------- % handclaws \foreach \i in {-4,-3.8,-3.6,3.9,3.7,3.5} { \pic [rotate = 180] at (\i,-6.5) {claw};} % left arm \path [draw, fill] (-3, -1) .. controls (-5.5,-3.5) and (-4.5,-7.5) .. (-3.35,-6.45); % right arm \path [draw, fill] (3, -1) .. controls (5.5,-3.5) and (4.5,-7.5) .. (3.35,-6.45); %------------------------belly---------------------------------- \draw[fill = bellycolor] ($(0,-4.7)+(230:3.8 and 4)$) to [out = -10,in = 190] ($(0,-4.7)+(-50:3.8 and 4)$) to ($(0,-4)+(-50:4.5)$) to [out = 60, in = -70] ($(0,-4.7)+(50:3.8 and 4)$) arc (50:130:3.8 and 4) to [out = -110, in = 120] ($(0,-4)+(-130:4.5)$) to cycle; % fur spots \foreach \i/\j/\k in {0/0/-1.3, -15/1.6/-1.5, 15/-1.6/-1.5, -8/0.7/-2.2, 8/-0.7/-2.2, -22/2.2/-2.5, 22/-2.2/-2.5} { \pic [rotate = \i] at (\j, \k) {furspot};} %------------------------legs and feet-------------------------- %legs \path [draw, rotate = 32, fill] (-5.8,-5.2) circle (0.9 and 1.4); \path [draw, rotate = -32, fill] (5.8,-5.2) circle (0.9 and 1.4); % left feet \path [draw, fill, rotate = 30] (-5.6,-6.1) circle (0.65 and 0.6); \path [draw, fill, rotate = -30] (5.6,-6.1) circle (0.65 and 0.6); % toe beans \path [draw, fill = bodycolor!50!white, rotate = 45] (-7,-4.7) circle (0.3 and 0.17); \path [draw ,fill = bodycolor!50!white, rotate = -45] (7,-4.7) circle (0.3 and 0.17); % footclaws \foreach \i/\j/\k in {50/-2.2/-7.9,40/-2/-7.7,30/-1.75/-7.55, -50/2.3/-8,-40/2.1/-7.8,-30/1.85/-7.65} { \pic [rotate = \i] at (\j,\k) {claw};} % hat \path [draw, fill = red] (43:2.5) to [in = -170, out = 130] ($(0.7,3)+(195:0.4)$) to [in = 180, out = 90] (0.7,3.1) to [out = 150, in = 0] (0,3.3) to [in = 50, out = 180] (137:2.5); \fill [draw, plush, fill = white, thin] (145:2.5 and 2) to [in = 160, out = 20] (35:2.5 and 2) to [out = 80, in = -80] ++(0,0.5) to [out = 160, in = 20] ($(145:2.5 and 2) +(0,0.5)$) to [in = 100, out = -100] cycle; \fill [draw, plush, fill = white, thin] (0.7,3.1) circle (0.5); \end{tikzpicture} \end{document}

mandelbrot.tex

\documentclass[border=10pt]{standalone} \usepackage{pgfplots} \pgfplotsset{width=7cm,compat=1.8} \usepackage{luacode} \begin{luacode} function mandelbrot(cx,cy, max_iter, max) local x,y,xtemp,ytemp,squaresum,iter squaresum = 0 x = 0 y = 0 iter = 0 while (squaresum <= max) and (iter < max_iter) do xtemp = x * x - y * y + cx ytemp = 2 * x * y + cy x = xtemp y = ytemp iter = iter + 1 squaresum = x * x + y * y end local result = 0 if (iter < max_iter) then result = iter end -- result = squaresum -- io.write("" .. cx .. ", " .. cy .. " = " .. result .. " (iter " .. iter .. " squaresum " .. squaresum .. ") \string\n") tex.print(result); end \end{luacode} \begin{document} \begin{tikzpicture} \begin{axis}[ colorbar, point meta max=30, tick label style={font=\tiny}, view={0}{90}] \addplot3 [surf,domain=-1.5:0.5,shader=interp,domain y=-1:1,samples=200] { \directlua{mandelbrot(\pgfmathfloatvalueof\x,\pgfmathfloatvalueof\y,10000,4)} }; \end{axis} \end{tikzpicture} \end{document}

・PDF生成に時間がかかる。

julia.tex

%!TEX lualatex \documentclass[border=5pt]{standalone} \usepackage{pgfplots} \pgfplotsset{width=7cm,compat=1.8} \usepackage{luacode} \begin{luacode} function julia(cx,cy, max_iter, max) local x,y,xtemp,ytemp,squaresum,iter squaresum = 0 x = cx y = cy iter = 0 while (squaresum <= max) and (iter < max_iter) do xtemp = x * x - y * y - 0.742 ytemp = 2 * x * y + 0.1 x = xtemp y = ytemp iter = iter + 1 squaresum = x * x + y * y end local result = 0 if (iter < max_iter) then result = iter end -- result = squaresum -- io.write("" .. cx .. ", " .. cy .. " = " .. result .. " (iter " .. iter .. " squaresum " .. squaresum .. ") \string\n") tex.print(result); end \end{luacode} \begin{document} \begin{tikzpicture} \begin{axis}[ colormap/hot2, colorbar, axis equal, point meta max=50, tick label style={font=\tiny}, view={0}{90}] \addplot3 [surf, domain = -1.82:1.82, shader = interp, domain y = -1.5:1.5, samples = 350] {\directlua{julia(\pgfmathfloatvalueof\x,\pgfmathfloatvalueof\y,10000,4)} }; \end{axis} \end{tikzpicture} \end{document}

・PDF生成に時間がかかる。

build/preview

.texを読み込むと、画面の上の右側にアイコンが並ぶ。右矢印のアイコンが「Build LaTeX project」、その右のアイコンが「Preview LaTeX PDF」になる。右矢印をクリックするとbuildが開始され終了するとPDFが生成される。 その後「Preview LaTeX PDF」をクリックすると画面の右側にPDFの内容がプレビューされる。
ファイル保存([Ctrl]+[S])を行っても自動的にbuildが実行される。
なお、build中は画面の最下行にbuild中を表す回転マークが表示され、 終了するとチェックマークに変わる。

参考情報

James-Yu/LaTeX-Workshop
LaTeX Workshopってなに?どうやって使うの?調べてみた!
User and Workspace Settings
【LuaTeX】LuaTeXテンプレート
「pLaTeXからLuaLaTeXへの移行」に関するクイズ

samples:
http://www.damp.tottori-u.ac.jp/~hoshi/info/doc-info-2009/sample.tex
TeX Wiki / LaTeX入門/最初の例
The recent 10 examples
Fraktale mit pgfplots

以上

続きを読む "vscodeでtexを編集する(lualatex)"

| | コメント (0)