来自文件的变更日志

来自文件的变更日志

我正在尝试在模板中获取一个非常好的变更日志表,并尝试使用目录方式(即写入文件然后从中读取)来实现。这种方法效果很好,但是据我所知,它不允许我将这些行写入真正的表格(因此不是 toc,而是 tabu 或 tabularx)。

这里有谁能帮助我吗?

以下是我尝试过的:

\documentclass{article}
\usepackage{hyperref}
\usepackage{verbatim}
\usepackage{tabu}
\makeatletter
\newcommand{\l@changelogline[2]}{
    #2\\
}
\makeatother

\newcommand{\changelog}{
    %\csname @starttoc\endcsname{cl}%
    \begin{tabu} spread \textwidth {l l l X[l]}
        \csname @starttoc\endcsname{cl}%    
    \end{tabu}
}
\addcontentsline{cl}{changelogline}{V0.1 & 21-02-2018 & Foitn & Initial version}
\addcontentsline{cl}{changelogline}{V0.2 & 22-02-2018 & Foitn & Some kind of change}
\begin{document}
    asdf
    \bigskip
    \changelog
\end{document} 

现在它给了我这个错误:

Missing } inserted. ...18 & Foitn & Initial version}{1}{Doc-Start}
Missing \endgroup inserted. ...18 & Foitn & Initial version}{1}{Doc-Start}

答案1

这是我用来创建文件的代码。它不会写入 *.aux 文件,而是直接写入\jobname.cl

\documentclass{article}
\usepackage{hyperref}
\usepackage{verbatim}
\usepackage{tabu}
\makeatletter
\newwrite\@changelog
\newcommand*\changelog@filename{\jobname.cl}
\newcommand*\changelog
  {%
    \IfFileExists{./\changelog@filename}
      {%
        \begin{tabu} spread \textwidth {l l l X[l]}%
          \input{\changelog@filename}
        \end{tabu}%
      }{}%
  }
\newcommand*\changelog@contents{}
\newcommand*\addchangelogline[4]
  {%
    \xdef\changelog@contents
      {%
        \unexpanded\expandafter{\changelog@contents
          #1 & #2 & #3 & #4\string\\
        }%
      }%
  }
\AtEndDocument
  {%
    \immediate\openout\@changelog=\changelog@filename
    \immediate\write\@changelog{\changelog@contents}%
    \immediate\closeout\@changelog
  }
\makeatother
\addchangelogline{v0.1}{21-02-2018}{Foitn}{Initial version}
\addchangelogline{v0.2}{22-02-2018}{Foitn}{Some kind of change}
\begin{document}
  asdf
  \bigskip
  \changelog
\end{document} 

工作使用方式\addtocontents等:

\documentclass{article}
\usepackage{hyperref}
\usepackage{verbatim}
\usepackage{tabu}
\makeatletter
\newwrite\@changelog
\newcommand*\changelog@extension{cl}
\newcommand*\changelog@filename{}
\edef\changelog@filename{\jobname.\changelog@extension}
\newcommand*\changelog
  {%
    \IfFileExists{./\changelog@filename}
      {%
        \begin{tabu} spread \textwidth {l l l X[l]}%
          \input{\changelog@filename}
        \end{tabu}%
      }{}%
      \bgroup
      \renewcommand*\changelogline[4]{}%
      \@starttoc{\changelog@extension}%
      \egroup
  }
\newcommand*\changelog@contents{}
\newcommand*\changelogline[4]{#1 & #2 & #3 & #4\\}
\newcommand*\addchangelogline[4]
  {%
    \addtocontents{\changelog@extension}
      {\protect\changelogline{#1}{#2}{#3}{#4}}%
  }
%\show\@starttoc
\makeatother
\addchangelogline{v0.1}{21-02-2018}{Foitn}{Initial version}
\addchangelogline{v0.2}{22-02-2018}{Foitn}{Some kind of change}
\begin{document}
  asdf
  \bigskip
  \changelog
\end{document}

相关内容