我正在做一个.dtx
项目,我可能会在 中嵌入数据以.dtx
写入几个.csv
文件。我遇到的问题是,在每个 的第一行输出之前插入了一个换行符.csv
。这在 的开头显示为一个空行。除非我编写一个复杂的捕获例程(我试图避免这种情况),否则.csv
当我的包从 读取时,这可能会造成问题。.csv
有没有办法让实际数据的第一行成为的第一行.csv
?
以下是的 MWE .dtx
:
% \iffalse meta-comment
% !TEX program = pdfLaTeX
%<*internal>
\iffalse
%</internal>
%<*readme>
----------------------------------------------------------------
A test file
----------------------------------------------------------------
This package is a test.
%</readme>
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
\expandafter\begingroup
\fi
%</internal>
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\preamble
----------------------------------------------------------------
A test file
----------------------------------------------------------------
\endpreamble
\postamble
Copyright (C) 2015 by test file
\endpostamble
\usedir{./}
\generate{
\file{\jobname.sty}{\from{\jobname.dtx}{package}}
}
%</install>
%<install>\endbatchfile
%<*internal>
\usedir{./}
\generate{
\file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
\nopreamble\nopostamble
\usedir{./}
\generate{\file{README.}{\from{\jobname.dtx}{readme}}}
\nopreamble\nopostamble
\generate{\file{csvfirst.csv}{\from{\jobname.dtx}{csv1}}}
\nopreamble\nopostamble
\generate{\file{csvsecond.csv}{\from{\jobname.dtx}{csv2}}}
\ifx\fmtname\nameofplainTeX
\expandafter\endbatchfile
\else
\expandafter\endgroup
\fi
%</internal>
%
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{csvtesterstuff}[2015/08/28 v0.01 LaTeX package for incorporating csv data in dtx]
\RequirePackage{pythontex}
\RequirePackage{siunitx}
%</package>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{\jobname}
\usepackage[numbered]{hypdoc}
\usepackage{isotope}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%
%</driver>
% \fi
%
%\GetFileInfo{\jobname.sty}
%
%\title{^^A
% \textsf{csvtest} --- provides a test for csv inclusion\thanks{^^A
% This file describes version \fileversion, last revised \filedate.^^A
% }^^A
%}
%\author{^^A
% testing\thanks{E-mail: testing}^^A
%}
%\date{Released \filedate}
%
%\maketitle
%
%\changes{v0.01}{2015/08/28}{First public release}
%
% Testing the inclusion of csv data in a .dtx file.\par
%
%\DescribeMacro{\stub}
% This is a stub.
%~
%
%~
%
%\StopEventually{^^A
% \PrintChanges
% \PrintIndex
%}
% \iffalse
%<*package>
%<<pythoncode
\begin{pycode}
import sys
import fileinput
import csv
from subprocess import check_output
u2Mev=931.502
u2kev=u2Mev*1000.
Mev2u=1.0/u2Mev
kev2u=1.0/u2kev
u2kg=1.660539e-27
kg2u=1.0/u2kg
\end{pycode}
%pythoncode
%\begin{macro}{\stub}
% \begin{macrocode}
\newcommand{\stub}{This is a stub.}
% \end{macrocode}
%\end{macro}
%<<endinput
\endinput
%endinput
%</package>
%<*csv1>
bill,2,1,Bo,3.123
sally,3,2,Sa,4.323
%</csv1>
%
%<*csv2>
Hydrogen,H,1
Uranium,U,92
%</csv2>
% \fi
%\Finale
答案1
任何在 guards 之外的空白行都可以。你有
%\StopEventually{^^A
% \PrintChanges
% \PrintIndex
%}
% \iffalse
%<*package>
%<<pythoncode
应该是
%\StopEventually{^^A
% \PrintChanges
% \PrintIndex
%}
% \iffalse
%<*package>
%<<pythoncode
做出改变,你的杂散线就会消失。