0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LaTeXでソースコードを挿入する方法のメモ(2024)

Posted at

和文(日本語)混じりのソースコードをLaTeX文章に貼り込むには、これまでいくつかの方法が紹介されてきましたが、近年(TeXLive2024)では、必要とされているスタイルファイル(jlisting.sty)が入手しにくくなっていたり、使えるとされていたもの(jvlisting)がエラーとなったりしていて、状況が混乱しているように思えます。

で、個人的に対策をまとめたのが以下。

  • lualatex を使えば listings パッケージを使うだけで問題は起きない
  • uplatex の場合は plistings.styをダウンロードしてきてtexファイルと同じところに置き、\usepackage{plistings} などとして使う
  • ソースコード番号やキャプションなどが不要であるなら、fvextra パッケージで \VerbatimInput 命令を使う。書きぶりとしては例えばこんな感じ\VerbatimInput[frame=lines,numbers=left,tabsize=4,breaklines,breakanywhere]{file/sample.c}

今のところこんなところっぽいです。

plistings はCTAN入りしてもいいと思うんですけど、入ってないってことは何か理由があるんでしょうか。それは追い切れてません。

以上、取り急ぎ

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?