同步日志输出

同步日志输出

在流程图中,多个流程可以同时汇集在一起​​,同步点,两个过程都必须先到达任何事物可以继续。当运行大量使用日志(用于调试目的)的 LaTeX 文件时,我的一些调试输出会与正在加载的文件列表混合在一起。

这是可以预料到的吗(是的,当然,但为什么呢?)并且是否可以在调试日志通过之前强制刷新“标准输出”?

示例 LaTeX 文件

\documentclass{article}

\makeatletter
%%% Begin package propbox
\RequirePackage{xparse}
\RequirePackage{expl3}
\ExplSyntaxOn

\def\propboxdebugmodeon { \def\if_propbox_debug { \iftrue } }
\def\propboxdebugmodeoff { \def\if_propbox_debug { \iffalse } }
\def\propbox_if_debug #1 { \if_propbox_debug #1 \fi }
\def\propbox_debug_msg #1 { \propbox_if_debug { \typeout{#1} } }

%% box collection
%% holds a list of tokens that save boxes
\seq_new:c { propbox_boxes_seq }

%% Property list
%% Comma-separated list of properties
\clist_new:c { propbox_properties_clist }

% inserts #1 into a the sequence with #2's properties
\cs_new_protected:Npn { \g_propbox_new_box } #1 #2 {
  % creates a new save box of the name `propbox_boxnames_N' where N is
  % the current number of items in the collection---0--\infty.
  \tl_set:Nn \l_tmpa_tl { propbox_boxnames_\seq_count:N \propbox_boxes_seq }
  \newsavebox { \use:c { \l_tmpa_tl } }
  \savebox { \use:c { \l_tmpa_tl } } {
    \begin{minipage}{\linewidth}
      #2
    \end{minipage}
  }
  \seq_push:Nv { \propbox_boxes_seq } { \use:c { \l_tmpa_tl } }
}

\NewDocumentCommand{\DeclareBoxProperty}{m}{
  \propbox_debug_msg { Declaring~new~set~of~box~properties... }
  \clist_set:Nn \propbox_properties_clist { #1 }
  \propbox_properties_update
  \propbox_debug_msg { Complete!~Here~are~the~new~properties: }
  \propbox_if_debug { \clist_show:N \propbox_properties_clist }
}

% updates the list of properties a box can have
\cs_new_protected:cpn { propbox_properties_update } {
  \propbox_debug_msg { Implementing~new~properties~for~boxes... }
  \clist_show:N \propbox_properties_clist
  \clist_map_inline:Nn \propbox_properties_clist {
    \propbox_debug_msg { Adding~key~'##1' }
    \tl_set:Nn \l_tmpa_tl { l_propbox_box_properties__##1 }
    \keys_define:nn { propbox / box_properties } {
      ##1 .tl_set:c = { \l_tmpa_tl }
    }
  }

  \propbox_debug_msg { Done. }
}


\ExplSyntaxOff
\propboxdebugmodeon
\DeclareBoxProperty{id,difficulty}
%%% End package
\makeatother

\propboxdebugmodeon
\begin{document}
\DeclareBoxProperty{hello,goodbye}
\end{document}

及其日志输出:

This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/W32TeX)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2011/06/27>
Babel <3.9f> and hyphenation patterns for 78 languages loaded.
(./test.tex (c:/texlive/2013/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(c:/texlive/2013/texmf-dist/tex/latex/base/size10.clo))
(c:/texlive/2013/texmf-dist/tex/latex/l3packages/xparse/xparse.sty
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/expl3.sty
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3names.sty
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3bootstrap.sty))
(c:/texlive/2013/texmf-dist/tex/latex/etex-pkg/etex.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3basics.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3expan.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3tl.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3seq.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3int.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3quark.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3prg.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3clist.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3token.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3prop.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3msg.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3file.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3skip.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3keys.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3fp.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3box.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3coffins.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3color.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3luatex.sty)
(c:/texlive/2013/texmf-dist/tex/latex/l3kernel/l3candidates.sty)
(c:/texlive/2013/texmf-dist/tex/generic/oberdiek/ifpdf.sty)))
Declaring new set of box properties...
Implementing new properties for boxes...
The comma list \propbox_properties_clist contains the items (without outer
braces):
>  {id}
>  {difficulty}.
<recently read> }

l.74 \DeclareBoxProperty{id,difficulty}

Adding key 'id'
Adding key 'difficulty'
Done.
Complete! Here are the new properties:
The comma list \propbox_properties_clist contains the items (without outer
braces):
>  {id}
>  {difficulty}.
<recently read> }

l.74 \DeclareBoxProperty{id,difficulty}

(./test.aux) (c:/texlive/2013/texmf-dist/tex/latex/graphics/graphics.sty
(c:/texlive/2013/texmf-dist/tex/latex/graphics/trig.sty)
(c:/texlive/2013/texmf-dist/tex/latex/latexconfig/graphics.cfg)
(c:/texlive/2013/texmf-dist/tex/latex/pdftex-def/pdftex.def
(c:/texlive/2013/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(c:/texlive/2013/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)
(c:/texlive/2013/texmf-dist/tex/context/base/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
))) (c:/texlive/2013/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
(c:/texlive/2013/texmf-dist/tex/generic/oberdiek/ifluatex.sty))
(c:/texlive/2013/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
(c:/texlive/2013/texmf-dist/tex/latex/oberdiek/grfext.sty
(c:/texlive/2013/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty))
(c:/texlive/2013/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(c:/texlive/2013/texmf-dist/tex/latex/graphics/keyval.sty)
(c:/texlive/2013/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(c:/texlive/2013/texmf-dist/tex/generic/oberdiek/etexcmds.sty)))
(c:/texlive/2013/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
Declaring new set of box properties...
Implementing new properties for boxes...
The comma list \propbox_properties_clist contains the items (without outer
braces):
>  {hello}
>  {goodbye}.
<recently read> }

l.80 \DeclareBoxProperty{hello,goodbye}

Adding key 'hello'
Adding key 'goodbye'
Done.
Complete! Here are the new properties:
The comma list \propbox_properties_clist contains the items (without outer
braces):
>  {hello}
>  {goodbye}.
<recently read> }

l.80 \DeclareBoxProperty{hello,goodbye}

(./test.aux) )
(see the transcript file for additional information)
No pages of output.
Transcript written on test.log.

LaTeX exited abnormally with code 1 at Sun Aug 11 20:00:50

答案1

\begin{document}日志文件告诉我们,有些包裹在

(./test.aux)

您可以graphicx在执行第一个操作之前明确地加载\DeclareBoxProperty,但不能保证某些操作\AtBeginDocument不会产生输出。

更好的策略是限定您的调试信息并使用诸如 Perl 之类的工具来查看它。

这是一种可能的使用策略\typeout(但最好利用这些\msg...功能)。

\documentclass{article}

\makeatletter
%%% Begin package propbox
\RequirePackage{xparse}
\ExplSyntaxOn

\bool_new:N \l_propbox_debug_bool

\NewDocumentCommand\propboxdebugmodeon {}
 { \bool_set_true:N \l_propbox_debug_bool }
\NewDocumentCommand\propboxdebugmodeoff {}
 { \bool_set_false:N \l_propbox_debug_bool }
\cs_new:Npn \propbox_if_debug:n #1 
 { \bool_if:NT \l_propbox_debug_bool { #1 } }
\cs_new_protected:Npn \propbox_debug_msg:n #1
 {
  \propbox_if_debug:n
   {
    \typeout{---~propbox~debug~start~---}
    \typeout{#1}
    \typeout{---~propbox~debug~end~---}
   }
 }

%% box collection
%% holds a list of tokens that save boxes
\seq_new:N \g_propbox_boxes_seq

%% Property list
%% Comma-separated list of properties
\clist_new:N \g_propbox_properties_clist

% inserts #1 into a the sequence with #2's properties
\cs_new_protected:Npn \propbox_new_box:nn #1 #2
 {
  % creates a new save box of the name `propbox_boxnames_N' where N is
  % the current number of items in the collection---0--\infty.
  \box_new:c { g_propbox_boxnames_ \seq_count:N \g_propbox_boxes_seq _box }
  \hbox_set:cn { g_propbox_boxnames_ \seq_count:N \g_propbox_boxes_seq _box }
   {
    \begin{minipage}{\linewidth}
      #2
    \end{minipage}
   }
  \seq_gput_left:Nx \g_propbox_boxes_seq
   { g_propbox_boxnames_ \seq_count:N \g_propbox_boxes_seq _box }
}

\NewDocumentCommand{\DeclareBoxProperty}{m}
 {
  \propbox_declare_box_property:n { #1 }
 }
\cs_new_protected:Npn \propbox_declare_box_property:n #1
 {
  \propbox_debug_msg:n { Declaring~new~set~of~box~properties... }
  \clist_gset:Nn \g_propbox_properties_clist { #1 }
  \propbox_properties_update:
  \propbox_debug_msg:n { Complete!~Here~are~the~new~properties: }
  \propbox_if_debug:n { \clist_show:N \g_propbox_properties_clist }
}

% updates the list of properties a box can have
\cs_new_protected:Npn \propbox_properties_update:
 {
  \propbox_debug_msg:n { Implementing~new~properties~for~boxes... }
  \clist_show:N \g_propbox_properties_clist
  \clist_map_inline:Nn \g_propbox_properties_clist
   {
    \propbox_debug_msg:n { Adding~key~'##1' }
    \tl_set:Nn \l_tmpa_tl { l_propbox_box_properties_##1 }
    \keys_define:nn { propbox / box_properties }
     {
      ##1 .tl_set:c = { l_propbox_box_properties_##1 }
     }
  }

  \propbox_debug_msg:n { Done. }
}


\ExplSyntaxOff
\propboxdebugmodeon
\DeclareBoxProperty{id,difficulty}
%%% End package
\makeatother

\propboxdebugmodeon
\begin{document}
\DeclareBoxProperty{hello,goodbye}
\end{document}

我做了其他更改以使代码符合指南。

相关内容