Skip to content

Instantly share code, notes, and snippets.

@NXVZBGBFBEN
Last active July 2, 2023 03:34
Show Gist options
  • Save NXVZBGBFBEN/9801c3f29b7937a8d748043b37958b84 to your computer and use it in GitHub Desktop.
Save NXVZBGBFBEN/9801c3f29b7937a8d748043b37958b84 to your computer and use it in GitHub Desktop.
ソースコードを記述する

なにこれ

文書の中にプログラムのコードを記述する場合のテンプレートです.
minted パッケージを使用する方法です.詳しい内容はググれば出てくると思います. (他力本願)

事前準備

  1. Python 2.6 以上をインストールする
  2. Pygmentsパッケージをインストールする

備考

  • $\mathrm{\LaTeX}$ソースファイル内に記述もできますが,インデント等が面倒なので外部ファイルを読み込むことをおすすめします.
  • コンパイラ引数として--shell-escapeが必要になります.
#include <stdio.h>
int main(void) {
int i = 1, j = 1, k = 1, l = 4, m = 1;
while (i <= 3) {
while (j <= 5) {
while (k <= i) {
while (l >= j) {
printf(" ");
--l;
}
while (m <= j) {
printf("*");
++m;
}
l = 4;
m = 1;
++k;
}
printf("\n");
k = 1;
++j;
}
j = 1;
++i;
}
return 0;
}
\documentclass{ltjsarticle}
\usepackage[no-math, deluxe, expert, haranoaji]{luatexja-preset}
\usepackage[outputdir=./out/]{minted} % outputdir でファイルの出力先ディレクトリ指定
\setmonofont{Inconsolatazi4} % フォント選択
\usemintedstyle{friendly} % スタイルのプリセット選択
\setminted[]{%
linenos=true, % 行番号を表示
frame=single, % フレーム設定
baselinestretch=0.8, % 行間サイズ設定(倍率)
}
\begin{document}
\inputminted{c}{./Code.c} % 外部ファイル読み込み
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment