
나는 egreg 좋은 대답을 시도하고있었습니다여기내 기본 문서에서 작동하지 않는 것을 발견했습니다. 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}
다시 컴파일하면 제대로 작동하고 예상한 결과를 얻을 수 있습니다. 오류가 없습니다.
breqn
egreg 명령을 유지하면서 계속 사용할 수 있는 방법이 있습니까 \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
자동 calc
으로 로드된 것입니다. 이는 기본 요소 이고 LaTeX 커널에 정의되어 있기 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이 인쇄됩니다.