\message: 改行があっても新しい行の前に記号を追加します

\message: 改行があっても新しい行の前に記号を追加します

私が行った場合:

\message{^^J! my very long message that will be cut on many lines because LaTeX for some weird reasons like to manually cut the lines instead of letting the terminal do it^^J}

ログには次のような内容が表示されます:

! my very long message that will be cut on many lines because LaTeX for some we
ird reasons like to manually cut the lines instead of letting the terminal do i
t

!しかし、 TeXstudio は a で始まる行のみをエラーとして印刷するため、すべての行の先頭に追加したいと思います!。ログに新しい行が作成されたときに、どのようにすれば自動的にシンボルを追加できるでしょうか?

ムウェ

\documentclass[]{article}


\begin{document}

\message{! my very long message that will be cut on many lines because LaTeX for some weird reasons like to manually cut the lines instead of letting the terminal do it}


\end{document}

編集: 明確にするために、ログに次の内容を含めたいと思います:

! my very long message that will be cut on many lines because LaTeX for some we
! ird reasons like to manually cut the lines instead of letting the terminal do
! it

(単語の境界で区切れたらもっといいのですが、まあ、あまり求めすぎないようにしましょう)

答え1

\xmessageここで、拡張メッセージを受け取り、設定された制限 (ここでは 40 文字) を超える最初のスペースでメッセージを分割するを紹介します。新しい行はそれぞれ!文字で始まります。

内の任意のコマンド シーケンスは\xmessage1 文字としてのみカウントされることに注意してください。

\documentclass[]{article}
\usepackage{tokcycle}
\newcounter{charcount}
\makeatletter
\newcommand\xmessage[1]{\bgroup%
  \aftertokcycle{\typeout{! \the\cytoks}}%
  \tokcycle{\addcytoks{##1}\stepcounter{charcount}}
  {\processtoks{##1}}
  {\addcytoks{##1}\stepcounter{charcount}}
  {\addcytoks{##1}\stepcounter{charcount}\splitline}{#1}%
  \egroup}
\newcommand\splitline{%
  \ifnum\value{charcount}>40\typeout{! \the\cytoks}%
  \setcounter{charcount}{0}\cytoks{}\fi}
\begin{document}
\xmessage{my very long message that will be cut on many lines because LaTeX for some weird reasons like to manually cut the lines instead of letting the terminal do it}
\end{document}

ここに画像の説明を入力してください

答え2

入力を*スペースで分割し (-variant を使用して完全展開した後でも可能)、行の合計の長さを計算し、制限max_print_lineを超えた場合に改行するかどうかを決定するメッセージを準備します。

\documentclass{article}

\ExplSyntaxOn

% get the current length of error lines
\sys_get_shell:nnN { kpsewhich ~ -var-value=error_line } {} \l_tmpa_tl
\int_const:Nn \c__tobiasbora_prefixmessage_limit_int { \l_tmpa_tl }

\NewDocumentCommand{\prefixmessage}{sO{!}m}
 {
  \IfBooleanTF { #1 }
   {
    \tobiasbora_prefixmessage:ne { #2 } { #3 }
   }
   {
    \tobiasbora_prefixmessage:nn { #2 } { #3 }
   }
 }

\seq_new:N \l__tobiasbora_prefixmessage_text_seq
\str_new:N \l__tobiasbora_prefixmessage_text_str
\int_new:N \l__tobiasbora_prefixmessage_len_int

\cs_new_protected:Nn \tobiasbora_prefixmessage:nn
 {
  \seq_set_split:Nne \l__tobiasbora_prefixmessage_text_seq { ~ } { \tl_to_str:n { #2 } }
  % start up
  \str_set:Nn \l__tobiasbora_prefixmessage_text_str { #1 }
  \int_zero:N \l__tobiasbora_prefixmessage_len_int
  % prepare the string to output
  \seq_map_inline:Nn \l__tobiasbora_prefixmessage_text_seq
   {
    \int_add:Nn \l__tobiasbora_prefixmessage_len_int { \str_count:n { ##1 } + 1 }
    \int_compare:nNnTF
     { \l__tobiasbora_prefixmessage_len_int }
     >
     { \c__tobiasbora_prefixmessage_limit_int - \str_count:n { #1 } }
     {
      \str_put_right:Nn \l__tobiasbora_prefixmessage_text_str { ^^J #1 ~ ##1 }
      \int_set:Nn \l__tobiasbora_prefixmessage_len_int { \str_count:n { ##1 } + 1 }
     }
     {
      \str_put_right:Nn \l__tobiasbora_prefixmessage_text_str { ~ ##1 }
     }
   }
  % output
  \iow_term:e { ^^J \l__tobiasbora_prefixmessage_text_str ^^J }
 }
\cs_generate_variant:Nn \tobiasbora_prefixmessage:nn { ne }

\ExplSyntaxOff

\prefixmessage{my very long message that will be cut on many 
  lines because \LaTeX for some weird reasons like to manually
  cut the lines instead of letting the terminal do it}

\def\foo{(something in the middle)}

\prefixmessage*[>>>]{my very long message that will be cut on many 
  lines because LaTeX \foo\space for some weird reasons like to manually
  cut the lines instead of letting the terminal do it}

\stop

ターミナルとログファイルに出力

! my very long message that will be cut on many lines because \LaTeX for some
! weird reasons like to manually cut the lines instead of letting the terminal
! do it


>>> my very long message that will be cut on many lines because LaTeX
>>> (something in the middle) for some weird reasons like to manually cut the
>>> lines instead of letting the terminal do it

答え3

LaTeX3 を使用した別のバージョン: 行は で区切られ\robExtPrefixLogMessage(コード内で使用する場合は、私の CTAN ライブラリと共謀しない別の名前を選択してください)、 がプレフィックスとして付きます\robExtPrefixLogMessage

\def\robExtMessageWithPrefixNumberLines{^^J}%
\cs_new:Nn \robExt__message_with_prefix:n {
  \str_set:Nn \l_tmpa_str {#1}  
  \int_compare:nNnTF {\str_count:N \l_tmpa_str + \str_count:N \robExtPrefixLogMessage} > {78} {
    \typeout{\robExtPrefixLogMessage \str_range:Nnn \l_tmpa_str {1} {78 - \str_count:N \robExtPrefixLogMessage}\robExtMessageWithPrefixNumberLines}
    \robExt__message_with_prefix:x {\str_range:Nnn \l_tmpa_str {78 - \str_count:N \robExtPrefixLogMessage + 1} {-1}}
  }{
    \typeout{\robExtPrefixLogMessage \l_tmpa_str \robExtMessageWithPrefixNumberLines}
  }
}
\cs_generate_variant:Nn \robExt__message_with_prefix:n { x }

関連情報