
私はエグレッションを試していました。素晴らしい答えですここbreqn
メインドキュメントで試してみましたが、動作しませんでした。原因は、本当に必要な別のパッケージを使用していたためであることが判明しました。
breqn
なぜコマンドが壊れるのかは分かりません 。しかし、ここにMWEがあります
\documentclass[10pt,notitlepage]{article}
\usepackage{etoolbox}%see https://tex.stackexchange.com/questions/257621
\makeatletter
\newcommand{\shellcommand}[1]{\@@input"|#1"}
\makeatother
\usepackage{breqn}
\newcounter{c}
\begin{document}
\setcounter{c}{\shellcommand{id -g}}
\arabic{c}
\end{document}
コンパイルするlualatex -shell-esc foo.tex
とエラーが発生します
(/usr/local/texlive/2015/texmf-dist/tex/latex/tools/calc.sty)) (./foo2.aux)
("|id -g!"id: invalid option -- '!'
Try 'id --help' for more information.
Runaway argument?
! Paragraph ended before \@calc@pre@scan was complete.
<to be read again>
\par
l.1
そこに「!」が追加されていることに注意してください。
行をコメント化し\usepackage{etoolbox}
て再度コンパイルするだけで、動作し、期待どおりの結果が得られました。エラーはありません。
を保持したまま、egregコマンドbreqn
を使用できる方法はありますか?\shellcommand
パッケージを削除してコンパイルする場合breqn
:
>lualatex -shell-esc foo2.tex
This is LuaTeX, Version beta-0.80.0 (TeX Live 2015) (rev 5238)
\write18 enabled.
(./foo2.tex
LaTeX2e <2015/01/01> patch level 2
Babel <3.9l> and hyphenation patterns for 79 languages loaded.
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2015/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(./foo2.aux) ("|id -g") [1{/usr/local/texlive/2015/texmf-var/fonts/map/pdftex/up
dmap/pdftex.map}] (./foo2.aux))
264 words of node memory still in use:
2 hlist, 1 vlist, 1 rule, 2 glue, 40 glue_spec, 1 write nodes
avail lists: 1:4,2:12,3:3,4:22,6:11,7:1,9:6
<</usr/local/texlive/2015/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on foo2.pdf (1 page, 8298 bytes).
Transcript written on foo2.log.
>
PDF に1000
は期待どおりの内容が含まれています。
Linux Mint 12.2 上の TL 2015
答え1
エラーの原因は ではなくbreqn
、によって自動的にロードされる です。はプリミティブであり、 は LaTeX のカーネルで定義されているため、どちらともcalc
関係ありません。etoolbox
\@@input
\input
以下は本当に簡単な例です:
\documentclass{article}
\usepackage{calc}
\makeatletter
\newcommand{\shellcommand}[1]{\@@input"|#1"}
\makeatother
\newcounter{c}
\begin{document}
\setcounter{c}{\shellcommand{id -g}}
\arabic{c}
\end{document}
問題は がcalc
を再定義する方法にあるようです\setcounter
。そのため は-
マイナス記号として認識され、当然すべてが壊れます。回避策は次のとおりです。まず必要な値を計算し、それを一時マクロに保存します。
\documentclass{article}
\usepackage{xparse,catchfile}
\usepackage{calc}
\makeatletter
\DeclareExpandableDocumentCommand{\shellcommand}{om}{%
\IfNoValueTF{#1}
{\@@input"|#2"}
{\CatchFileEdef#1{"|#2"}{}}%
}
\makeatother
\newcounter{c}
\begin{document}
\shellcommand[\temp]{id -g}
\setcounter{c}{\temp}
\arabic{c}
\end{document}
私のマシンでは 20 と出力されます。