LaTeX 파일에서 주석을 제거하는 데 어려움을 겪고 있습니다.
나는 두 가지 주요 답변을 시도했습니다.이 질문, 하지만 작동하지 않습니다.
다음은 테스트 파일입니다.
é %comment
- 를 실행할 때
latexpand test.tex > stripped.tex
결과 파일의 인코딩에 문제가 있으며 PDF로 컴파일되지 않습니다.stripped.tex
다음과 같다:
é %
- 을(를 ) 실행하면 PATH에 정의되지 않았다는
arxiv-latex-cleaner \path\to\folder
오류가 발생합니다 . PATH에 있는 폴더가 있습니다 (즉 ). Windows 프롬프트와 Anaconda 프롬프트 모두에서 pip를 사용하여 제거하고 다시 설치했지만 소용이 없었습니다. 여전히 같은 오류가 발생합니다.arxiv-latex-cleaner
arxiv-latex-cleaner : The term 'arxiv-latex-cleaner' is not recognized as the name of a cmdlet, function, script file, or operable program.
arxiv_latex_cleaner.exe
C:\Users\MYNAME\AppData\Roaming\Python\Python39\Scripts
arxiv-latex-cleaner
Anaconda를 통해 Windows 10, Python 3.9를 설치하고 texlive를 통해 LaTeX를 설치했습니다.
답변1
(이것이 3번째 버전입니다)
이것을 파일로 저장하세요stripper.tex
% macro to sanitize catcodes, making space and % active
\def\stringregime{%
\catcode`\\ 12
\catcode`\{ 12
\catcode`\} 12
\catcode`\# 12
\catcode32 \active
\catcode`\~ 12
\catcode`\% \active
}%
% active space gives normal space
\begingroup
\catcode32\active\xdef {\string }%
\endgroup
\begingroup
% the \empty delimiter will be added manually by \handlelines
\catcode`\%\active
\xdef%#1\empty{\string%}
\endgroup
\def\removeEOLspacechar#1 {\def\fileline{#1}}
\def\bracedpar{\par}
% main loop macro
\def\handlelines{%
\ifeof\infile
\else
\read\infile to \fileline
% remove the EOL space from \fileline before outputting it
% If TeX replaces an empty line by \par in input there is no space
% token only the \par token.
\ifx\fileline\bracedpar\def\fileline{}\else
\expandafter\removeEOLspacechar\fileline
\fi
\immediate\write\outfile{\fileline\empty}% delimiter for active %
\expandafter\handlelines
\fi
}
% loop launch
\def\DoIt{%
\begingroup
\stringregime
\handlelines
\endgroup
}
% file auxiliaries
\newread\infile
\newwrite\outfile
\immediate\write128{}
\message{filename to strip of comments: }\read-1to\theinfile
% clean up trailing space
\def\cleanuptrailingspace#1 \par{\def\theinfile{#1}}
\expandafter\cleanuptrailingspace\theinfile\par
%
\openin\infile\theinfile\relax
\immediate\openout\outfile\theinfile-out
\DoIt
\immediate\write128{output written to \theinfile-out USE AT OWN RISK}
\immediate\closein\infile
\immediate\closeout\outfile
\bye
사용법: etex stripper
명령줄에서 실행하면 파일 이름을 묻는 메시지가 표시됩니다. 입력(으로 끝남 <return>
)하면 eTeX는 작업 레퍼토리의 새 파일에 출력을 생성합니다. 시작하려면 동일한 작업 레퍼토리에서 파일을 제거하십시오.
%
주석 문자 이외의 용도로 사용하면(예: \%
.) 몇 가지 제한 사항이 있으며 문제가 발생합니다.
이론적으로 이 코드는 모든 %
의 위치를 찾아 입력 줄에서 그 뒤에 오는 모든 항목을 잘라냅니다.
이 답변의 최신 버전과 비교하면 출력 파일 줄이 공백 문자로 끝나는 것을 방지합니다. (어쨌든 그것은 중요하지 않았습니다).