我有几个 tikz 时序图,我用包装胶乳文件编译。该包装器使用独立的 latex 包来生成 pdf 和 png 文件。我想保留所有这些包装文件并仅用一个替换它们。此外,我想将文件名列表通过管道传输到 PowerShell 函数中,该函数处理通用包装文件的每个波形 tex 文件。
更详细:
Waveform.tex
\input{...}
是包装 tex 文件,它在宏中有一个占位符。此占位符由 PowerShell 脚本替换。
\documentclass[convert={density=600,size=2000x800,outext=.png}]{standalone}
\usepackage[utf8]{inputenc} % UTF-8 tex file input incoding
\usepackage[T1]{fontenc} % Type1 font encoding
\usepackage[ngerman]{babel} % new german writing rules; must be loaded before microtype
\usepackage{courier} % set courier font as default for teletype writer (texttt, ttfamily, ...)
\usepackage[usenames,svgnames,table]{xcolor} % load colors and color-names
\usepackage{pgf} % primitive drawing library
\usepackage{tikz} % PGF frontend, drawing macros
\usepackage{tikz-timing} % spezial TikZ library for waveform/timing diagrams
\usetikztiminglibrary{nicetabs} % sublibrary for better looking timingtables
\begin{document}
\input{%%WaveformFile%%}
%\input{IICController} % uncomment this if timing-diagram is a fixed file name
\end{document}
IICController.tex 是示例波形:
%
\tikztimingmetachar{A}[1]{#1{Z[black]};}
%
\begin{tikztimingtable}[
timing/table/header/.style={font=\bf},
timing/wscale=2,
timing/nice tabs,
]
Master\_BusRequest & L H H 4H 4H 4H 4H L \\
Master\_BusGrant & L L H 4H 4H 4H 4H L \\
Master\_BusAbort & L L L 4L 4L 4L 4L L \\
Master\_WP\_Valid & L L L 4H 4H 4H 4H L \\
Master\_WP\_Data & A A A 4D{Phy Adr + R/W} 4D{Reg Adr} 4D{D0.0} 4D{D0.1} A \\
Master\_WP\_Last & L L L 4L 4L 4L 4H L \\
Master\_WP\_Ack & L L L 3LH 3LH 3LH 3LH L \\
\extracode
\tableheader{Signalname}{Signalverlauf}
\tablerules
\begin{background}[shift={(0.1,0)},help lines]
\vertlines{0,2,...,40}
\end{background}
\end{tikztimingtable}
最后,这是我的 PowerShell 脚本:
function Compile-Waveform
{ [CmdletBinding()]Param(
[Parameter(
Mandatory=$True,
Position=0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[String[]]$InputFiles
)
Begin
{ $WrapperFile = "Waveform.tex"
$WrapperContent = Get-Content -Path $WrapperFile -Encoding ASCII -Raw
}
Process
{ #Write-Host "WrapperContent" -ForegroundColor Green
#Write-Host $WrapperContent -ForegroundColor Gray
#Write-Host ""
foreach($InputFile in $InputFiles)
{ Write-Host "processing file: '$Inputfile'" -ForegroundColor Yellow
$OutputFile = [String]$InputFile.Replace(".tex", ".png")
$Temp = $WrapperContent -replace "%%WaveformFile%%",$InputFile
#Write-Host "Temp" -ForegroundColor Green
#Write-Host $Temp -ForegroundColor Gray
#Write-Host ""
Write-Output $Temp | & 'C:\Program Files\MiKTeX 2.9\miktex\bin\x64\pdflatex.exe' -shell-escape -time-statistics -synctex=1 -interaction=nonstopmode
}
}
}
如何使用脚本?
导航到 的文件夹IICController.tex
。获取 *.ps1 文件,最后将所有找到的波形文件通过管道传输到 PowerShell 函数中:
cd d:\temp\waveform
. compile.ps1
dir IICController.tex | Compile-Waveform
现在 pdflatex 将打印错误日志:
processing file: 'D:\git\SATAController\doc\Waveforms\Simple.tex'
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (MiKTeX 2.9 64-bit)
**entering extended mode
LaTeX2e <2014/05/01>
Babel <3.9l> and hyphenation patterns for 68 languages loaded.
! Emergency stop.
<*> ...600,size=2000x800,outext=.png}]{standalone}
! ==> Fatal error occurred, no output PDF file produced!
Transcript written on texput.log.
gross execution time: 26 ms
user mode: 0 ms, kernel mode: 15 ms, total: 15
puttex.log
与控制台输出的内容相同。
有谁知道发生了什么?
如果我在 PowerShell 中使用固定文件名(见第二\input
行)运行 Wavefom.tex,一切正常。