색상 전환 명령에서 빈 줄을 사용할 때 발생하는 문제

색상 전환 명령에서 빈 줄을 사용할 때 발생하는 문제

이것은 내 질문에 대한 후속 조치입니다.문서 일부의 색상 시스템을 변경하시겠습니까?

나는 문서를 파란색(또는 내가 원하는 색상)으로 정의한 다음 특정 환경에 맞게 색상을 다시 정상으로 전환하고 다시 전환하여 이 문제를 해결하려고 했습니다. 이는 예를 통해 더 명확해졌습니다. 그러나 내 문제는 색상 전환이 완벽하게 작동하는 것이 아닙니다.

내 문제는 새 명령에 빈 줄을 사용할 수 없다는 것입니다!

예를 들어

\iSol{ \lipsum[75] } 

완벽하게 작동하지만,

\iSol{ \lipsum[75]

\lipsum[66] }

누락된 것에 대해 불평합니다 par. 빈 줄을 사용할 수 있도록 명령을 수정하는 방법을 아시나요?

암호

\documentclass{article}

% Uses the default color profile from UiT's official guidelines

\usepackage{xcolor,lipsum}
\usepackage{xparse,etoolbox}
\newtoggle{isLF} 

\definecolor{UiT-main}{HTML}{003349}
\definecolor{UiT-red}{HTML}{CB333B}
\definecolor{UiT-blue}{HTML}{007396}
\definecolor{UiT-cyan}{HTML}{59BEC9}
\definecolor{UiT-orange}{HTML}{F2A900}
% The green is not default, but very useful
\colorlet{UiT-green}{green!50!black}
\colorlet{UiT-solution}{black}

\colorlet{UNI-default}{.}
\colorlet{UNI-current}{UNI-default}

\colorlet{UNI-monochrome}{black!50!white}

\newcommand{\resetUiTcolors}{
  \definecolor{UiT-main}{HTML}{003349}
  \definecolor{UiT-red}{HTML}{CB333B}
  \definecolor{UiT-blue}{HTML}{007396}
  \definecolor{UiT-cyan}{HTML}{59BEC9}
  \definecolor{UiT-orange}{HTML}{F2A900}
  % The green is not default, but very useful
  \colorlet{UiT-green}{green!50!black}
}

\newcommand{\monoUiTcolors}{
  \colorlet{UNI-monochrome}{black!50!white}

  \colorlet{UiT-solution}{black}

  \colorlet{UiT-main}{UNI-monochrome}
  \colorlet{UiT-red}{UNI-monochrome}
  \colorlet{UiT-blue}{UNI-monochrome}
  \colorlet{UiT-cyan}{UNI-monochrome}
  \colorlet{UiT-orange}{UNI-monochrome}
  % The green is not default, but very useful
  \colorlet{UiT-green}{UNI-monochrome}
}

\newcommand{\UNIfullcolor}[1]{
  \colorlet{UNI-default}{.}
  \resetUiTcolors
  \resetUNIhypersetup
  \color{UiT-solution}
  #1
  \monoUiTcolors
  \monoUNIhypersetup
  \color{UNI-default}
}

\DeclareDocumentCommand{\iSol}{m G{}}{
  \iftoggle{isLF}{
      \UNIfullcolor{#1}
  }{#2}
}

% Hyperlenker og klikkbare lenker.
\RequirePackage{hyperref}

\hypersetup{
  pdftoolbar=true,        % show Acrobat’s toolbar?
  pdfmenubar=false,       % show Acrobat’s menu?
  pdffitwindow=false,     % window fit to page when opened
  pdfstartview={FitH},    % fits the width of the page to the window
  linktoc=all,            % Link all the things in the toc
  colorlinks=true,        % false: boxed links; true: colored links
  linkcolor=black,        % color of internal links (change box color with linkbordercolor)
  citecolor=UiT-cite,        % color of links to bibliography
  filecolor=UiT-orange,      % color of file links
  urlcolor=UiT-url          % color of external links
}

\newcommand{\resetUNIhypersetup}{%
  \hypersetup{
    colorlinks=true,        % false: boxed links; true: colored links
    linkcolor=black,        % color of internal links (change box color with linkbordercolor)
    citecolor=UiT-cite,        % color of links to bibliography
    filecolor=UiT-orange,      % color of file links
    urlcolor=UiT-url          % color of external links
  }%
}
\newcommand{\monoUNIhypersetup}{%
  \hypersetup{
    colorlinks=true,        % false: boxed links; true: colored links
    linkcolor=UNI-monochrome,        % color of internal links (change box color with linkbordercolor)
    citecolor=UNI-monochrome,        % color of links to bibliography
    filecolor=UNI-monochrome,      % color of file links
    urlcolor=UNI-monochrome          % color of external links
  }%
}

\begin{document}

\color{blue}

\lipsum[5]

\settoggle{isLF}{true}

% this works
\iSol{\lipsum[75]}

% this dont

%\iSol{\lipsum[75]
%
%\lipsum[66]}

\lipsum[66]

\end{document}

답변1

LaTeX2e \newcommand기본적으로 매크로를 생성하는 반면 \long(별표 표시된 버전은 짧은 매크로를 생성) \DeclareDocumentCommand그 반대를 만듭니다. 매크로 인수에서 단락을 허용하려면 다음과 같이 지정자 앞에 a 를 붙여야 합니다 +.

\DeclareDocumentCommand{\iSol}{+m G{}}{% <-- don't forget this
  \iftoggle{isLF}{% <-- don't forget this
      \UNIfullcolor{#1}% <-- don't forget this
  }{#2}% <-- don't forget this
}

해당 버전은 의 버전 \DeclareDocumentCommand이므로 매크로가 존재하는지 확인하지 않습니다. 더 안전한 버전입니다.xparse\def\NewDocumentCommand

관련 정보