LoginSignup
2
2

Typstの始め方と使い方

Last updated at Posted at 2024-01-13

手順

  1. (Macです、Windowsでも同じようにできる?)
  2. brew install typstでインストール
  3. VS Code拡張機能「Typst LSP」をインストール

使い方(文書)

  1. 適当にmain.typみたいなのを作りましょう
  2. 以下のような書き込みをするだけで簡単に始められるます(1チャンク目はLaTeXのようなアウトプットが出るような設定で、2チャンク目は定理環境、3チャンク目はオリジナルコマンド)
  3. (その他の基本的なルールは適宜調べてください)
#set page(paper: "us-letter", margin: 1.5in)
#set par(leading: 0.55em, first-line-indent: 1.8em, justify: true)
#set text(font: "Linux Libertine", size:12pt)
#set heading(numbering: "1.")
#show par: set block(spacing: 1.10em) // double-spacing
#show heading: set block(above: 1.4em, below: 1em)

#import "@preview/ctheorems:1.1.0": *
#show: thmrules
#let thm = thmbox("theorem", "Theorem", fill: rgb("#FFCCCC"))
#let prop = thmbox("proposition", "Proposition", fill: rgb("#FFE5CC"))
#let exer = thmbox("exercise", "Exercise", fill: rgb("#CCFFCC"))
#let defn = thmbox("definition", "Definition", inset: (x: 0em, top: 1.1em))
#let proof = thmplain(
  "proof",
  "Proof",
  base: "theorem",
  bodyfmt: body => [#body #h(1fr) $square$]
).with(numbering: none)

#let ge = $gt.eq$



= Section #footnote[something]

== Subsection

=== Subsubsection
Hello world

- list
- list

inline math $f(x) = x$
math block $ f(x) = x $
math block (multi lines)
  $
    f(x)
    &= x(x-1) \
    &= x^2 - x
  $

normal text _emphasized text_

// commentout

#defn[
  definition
]

#thm("Euler")[
  theorem
] <thm-label>

By @thm-label, something.

使い方(スライド)

メトロポリスのテーマで作ってみた

ポイント

  • 英語はAvenir Next、日本語はヒラギノ角ゴシックで和欧混植している
  • dateが自動で今日に変わるようにしている
// https://polylux.dev/book/themes/gallery/metropolis.html#metropolis-theme
#import "@preview/polylux:0.3.1": *
#import themes.metropolis: *
#show: metropolis-theme.with(aspect-ratio: "4-3") // "4-3" or "16-9"
#set text(size: 24pt)
#set text(font: "Avenir Next")
#show regex("[\p{scx:Han}\p{scx:Hira}\p{scx:Kana}]"): set text(font: "Hiragino Kaku Gothic ProN", size: 22pt)
#set strong(delta: 100)
#set par(justify: true, leading: 0.65em)
#set list(marker: ([•], [◦], [-], [+]), spacing: auto)
#set block(below: 1.2em)
#let today = datetime.today()

#title-slide(
  author: [authors],
  title: "title",
  subtitle: "subtitle",
  date: today.display("[month repr:long] [day], [year]"),
  extra: "Extra notes"
)

#slide(title: "title name")[
  Lists
  - list
  - list

  Wide lists
  - list

  - list

  #alert[very important]
]

#new-section-slide("First section")

#focus-slide[
  FOCUS
]

Typstの仕様

リスト

  • 箇条書きの間を広げたかったら、シンプルに箇条書きごとに改行すれば良いらしい(ちがうブロックとみなされるので)
#slide[
  - list 1

  - list 2
]
  • 以下のような感じでもすべての箇条書き間が広がる
#slide[
  - list 1

  - list 2
  - list 3
]

コマンド

#let something = $something$でコマンドを作れます。
たとえば、#let cA = $cal(A)$で、cAにカリグラフィックAを割り当てられます。

イタリック表記の色を変えたい

#show emph: it => {text(blue, it.body)}で、_text_で普通の立体・色は青の「text」を出力できる

LaTeXとのコマンドの違い

このリストにない場合は、https://typst.app/docs/reference/symbols/sym/
Typstのコマンドのほうが好きだけど、LaTeXに慣れすぎてしまったので違いに少し困る...

LaTeX typst
\mathbb{A} AA
\mathcal{A} cal(A)
\cup union
\bigcup union.big
\cap sect
\bigcap sect.big
\ge gt.eq
\le lt.eq
\ne equiv.not
\cdots dots.h.c
\to arrow.r
\implies arrow.r.double.long
\setminus without
\pm plus.minus
\infty infinity
a \text{ and } b a "and" b
\bar{x} macron(x)
\textrm{Var} upright(V a r)
... ...

使えるフォント

ターミナルでtypst fontsと打てば自分が使えるフォントの一覧を見られる、もちろん日本語も

SyncTexみたいなことをする

VSCode拡張機能のTypst Previewをインストール
使い方は、コマンドパレットでTypst Preview: Preview current file in slide modeを選ぶだけ

使用感

  • マークダウンみたいにリアルタイム反映されるので嬉しい、圧倒的に便利
  • 1ページごと表示しかできなくて、シームレスな表示のやり方がわからない?
  • 日本語ではジャンプできない気がする?

Typstへの感想

  • コンパイラが爆速
  • \omegaじゃなくてomegaと打てたりと、コードがLaTeXより見やすい
  • 数式内の括弧の大きさが自動で変わるのが良い
  • 長い文章を書くのはまだLaTeXに分がある?
    • LaTeXのほうがコマンドが柔軟だと思う
  • スライドを作るときはTypstに分がある気がする
    • リストの作り方が簡単なので

疑問点など

  • \newcommand{\set}[1]{\{ #1 \}}みたいなことってできる?
    • #let bar(x) = macron(#x)みたいな感じでできる
  • underline(x)が数式では気持ち悪いから違うコマンド使いたい
  • デフォルトでリストの間隔を広くしたい(いちいち改行はさみたくない)
  • 全角括弧()の挙動がキモい気がする
  • DI(x)みたいな関数を書きたいときに、DI(x)とは書けなくてD I(x)D I (x)と書く必要がある
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2