
我試圖在我的模板中獲得一個非常好的變更日誌表,並且我試圖使用目錄方式來做到這一點(因此寫入檔案並隨後從中讀取)。這很好用,但是它不允許我(據我所知)將這些行寫入 REAL 表(所以不是目錄,而是像 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}