色切り替えコマンドで空行を使用する際の問題

色切り替えコマンドで空行を使用する際の問題

これは私の質問に対するフォローアップですドキュメントの一部のカラーシステムを変更しますか?

私はこの問題を解決するために、ドキュメントを青 (または任意の色) に定義し、特定の環境に合わせて色を通常の色に切り替え、その後、元に戻すという操作を試みました。これは例を見ればより明確になります。ただし、私の問題は色の切り替えではなく、問題なく機能することです。

問題は、新しいコマンドで空白行を使用できないことです。

例えば

\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その逆になります。マクロ引数で段落を許可するには、指定子の前に を付ける必要があります+。次の例をご覧ください。

\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

関連情報