Удаление комментариев в LaTeX

Удаление комментариев в LaTeX

Я пытаюсь удалить комментарии из файла LaTeX.

Я попробовал два основных ответа изэтот вопрос, но это не работает.

Вот тестовый файл:

é %comment
  1. При запуске latexpand test.tex > stripped.texвозникает проблема с кодировкой результирующего файла, и он не компилируется в PDF. stripped.texвыглядит следующим образом:
é %
  1. При запуске arxiv-latex-cleaner \path\to\folderвыдается ошибка, что arxiv-latex-cleanerне определено в PATH: 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), находится в PATH. Я удалил и переустановил arxiv-latex-cleanerс помощью pip, как в командной строке Windows, так и в командной строке Anaconda, но безрезультатно. Я все еще получаю ту же ошибку.

У меня Windows 10, Python 3.9 установлен через Anaconda, а LaTeX установлен через texlive.

решение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 выведет вывод в новом файле в рабочем реперториуме. Пожалуйста, для начала поместите файл, который нужно очистить, в тот же рабочий реперториум.

Существуют некоторые ограничения, и могут возникнуть проблемы, если %он используется не для комментариев (например, если есть точка \%.).

Теоретически этот код находит все %символы '' и обрезает все, что следует за ними во входных строках.

По сравнению с последней версией этого ответа, в этой версии строки выходного файла не заканчиваются пробелом (что в любом случае не имело значения).

Связанный контент