以纯文本形式输出 \layout

以纯文本形式输出 \layout

是否可以将\layout命令生成的尺寸作为纯文本获取,以便在 octave 等程序中生成图形时可以使用它来设置适当的大小。

pointsize= 0.35145980351/10;
% 373 happens to be the width of the text column in this particular
% case but it would change with different layout options, but I would 
% like to retrieve it from LaTeX instead
textwidth = 373*pointsize;
figwidth=0.8*textwidth;
figheight=0.6*figwidth;
fig=figure('paperunits','centimeters','papersize'...
    ,[figwidth figheight],'paperposition',[0 0 figwidth figheight]);

为了得到一些可以与之媲美的东西,我尝试了这个:

\newcommand{\geomdump}{
\newwrite\geometry
\openout\geometry=geometry\thesection.txt
\write\geometry{tex_section=\thesection;}
\write\geometry{tex_paperwidth=\paperwidth;}
\write\geometry{tex_paperheight=\paperheight;}
\write\geometry{tex_textwidth=\textwidth;}
\write\geometry{tex_textheight=\textheight;}
\write\geometry{tex_oddsidemargin=\oddsidemargin;}
\write\geometry{tex_evensidemargin=\evensidemargin;}
\write\geometry{tex_topmargin=\topmargin;}
\write\geometry{tex_headheight=\headheight;}
\write\geometry{tex_headsep=\headsep;}
\write\geometry{tex_topskip=\topskip;}
\write\geometry{tex_footskip=\footskip;}
\write\geometry{tex_marginparwidth=\marginparwidth;}
\write\geometry{tex_marginparsep=\marginparsep;}
\write\geometry{tex_columnsep=\columnsep;}
\write\geometry{tex_hoffset=\hoffset;}
\write\geometry{tex_voffset=\voffset;}
\write\geometry{tex_mag=\mag;}
\closeout\geometry
}
\let\oldsection\section
\renewcommand{\section}[1]{\oldsection{#1}
\geomdump
}

输出结果如下(第 1 部分)

tex_section=1;
tex_paperwidth=\paperwidth ;
tex_paperheight=\paperheight ;
tex_textwidth=\textwidth ;
tex_textheight=\textheight ;
tex_oddsidemargin=\oddsidemargin ;
tex_evensidemargin=\evensidemargin ;
tex_topmargin=\topmargin ;
tex_headheight=\headheight ;
tex_headsep=\headsep ;
tex_topskip=\topskip ;
tex_footskip=\footskip ;
tex_marginparwidth=\marginparwidth ;
tex_marginparsep=\marginparsep ;
tex_columnsep=\columnsep ;
tex_hoffset=\hoffset ;
tex_voffset=\voffset ;
tex_mag=\mag ;

问题:

  • 提取长度的宏在这里不起作用,但节计数器可用。我该如何解决这个问题?

  • 现在每个部分都有一个文件。是否可以将其附加到文件而不是创建新文件?

答案1

这是一个解决方案。

\openout\closeout在命令之外,否则文件将被覆盖。

\the<\length>:输入长度值。

笔记这是重新定义的糟糕方式\section

\documentclass{article}

\newwrite\mtgeometry
\immediate\openout\mtgeometry=mtfile.txt

\newcommand{\geomdump}{%
\immediate\write\mtgeometry{
tex_section=\thesection; ^^J
tex_paperwidth=\the\paperwidth; ^^J
tex_paperheight=\the\paperheight; ^^J
tex_textwidth=\the\textwidth; ^^J
tex_textheight=\the\textheight; ^^J
tex_oddsidemargin=\the\oddsidemargin; ^^J
tex_evensidemargin=\the\evensidemargin; ^^J
tex_topmargin=\the\topmargin; ^^J
tex_headheight=\the\headheight; ^^J
tex_headsep=\the\headsep; ^^J
tex_topskip=\the\topskip; ^^J
tex_footskip=\the\footskip; ^^J
tex_marginparwidth=\the\marginparwidth; ^^J
tex_marginparsep=\the\marginparsep; ^^J
tex_columnsep=\the\columnsep; ^^J
tex_hoffset=\the\hoffset; ^^J
tex_voffset=\the\voffset; ^^J
tex_mag=\the\mag; ^^J}}

\let\oldsection\section
\renewcommand{\section}[1]{%
\oldsection{#1}\geomdump}
\begin{document}
bla bla
\section{Foo}
\section{Bar}
\immediate\closeout\mtgeometry
\end{document} 

相关内容