\message: adiciona símbolo na frente de novas linhas mesmo se houver uma quebra de linha

\message: adiciona símbolo na frente de novas linhas mesmo se houver uma quebra de linha

Se eu fizer:

\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}

Verei algo assim no log:

! 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

Mas eu gostaria de acrescentar !todas as linhas, porque o TeXstudio só imprimirá linhas começando com !erros as. Como posso adicionar automaticamente um símbolo quando uma nova linha é criada no log?

MWE

\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}

EDIT: para esclarecer, gostaria que o log contivesse:

! 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

(ou melhor ainda, se pudesse quebrar os limites das palavras, mas ei, não vamos pedir muito)

Responder1

Aqui, apresento \xmessage, que pega uma mensagem estendida e a quebra no primeiro espaço que excede um limite definido (aqui 40 caracteres). Cada nova linha começa com um !caractere.

Observe que qualquer sequência de comandos fornecida \xmessageconta apenas como um único caractere.

\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}

insira a descrição da imagem aqui

Responder2

Divida a entrada (possivelmente após a expansão completa, com a *variante -) em espaços e então prepare a mensagem calculando o comprimento total da linha e tomando a decisão de quebrar se o max_print_linelimite for excedido.

\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

Saída no terminal e no arquivo de log

! 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

Responder3

Outra versão com LaTeX3: as linhas são separadas por \robExtPrefixLogMessage(se você usar em seu código, escolha outros nomes para não conspirar com minha biblioteca CTAN), e irá prefixá-la com \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 }

informação relacionada