\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로 시작하는 줄만 오류로 인쇄하기 때문에 모든 줄 앞에 추가하고 싶습니다 !. 로그에 새 줄이 생성될 때 자동으로 기호를 추가하려면 어떻게 해야 합니까?

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}

편집: 명확히 하기 위해 로그에 다음을 포함하고 싶습니다.

! 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자)을 초과하는 첫 번째 공백에서 나누는 를 소개합니다. 각각의 새 줄은 !문자로 시작됩니다.

only 의 특정 명령 시퀀스는 \xmessage단일 문자로 계산됩니다.

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

관련 정보