如何重新定义alertmessage包的命令?

如何重新定义alertmessage包的命令?

如何重新定义alertmessage包的命令?

软件包链接:https://www.ctan.org/tex-archive/macros/latex/contrib/alertmessage

\documentclass{book}
\usepackage{alertmessage}

%\renewcommand*\alertsuccess[1]{\alertmessage@panel{green}{img/alertmessage-success.png}{#1}}
 
\begin{document}

\alertinfo{hello}
\alertwarning{hello}
\alertsuccess{hello}
\alerterror{hello}

\end{document}

答案1

您已经足够接近了,但@您的文档中应该禁用该符号(即不是字母),以确保只有开发人员使用内部函数。您可以使用 重新启用该@符号\makeatletter <your code> \makeatother


\documentclass{book}
\usepackage{graphicx}
\usepackage{alertmessage}

\makeatletter
\renewcommand*\alertsuccess[1]{%
  \alertmessage@panel{green}{example-image-a}{#1}%
}%
\makeatother

\begin{document}

\alertinfo{hello}
\alertwarning{hello}
\alertsuccess{hello}
\alerterror{hello}

\end{document}

编辑

自定义尺寸版本:

\documentclass{book}
\usepackage{graphicx}
\usepackage{alertmessage}

\makeatletter

% ALERT PANEL, copied from https://github.com/pidupuis/latex-alert-message/blob/master/alertmessage.sty
\NewDocumentCommand{\alertmessage@panelcustom}{mmmO{}}{%
  \begin{center} %
    \noindent % No indentation
    \begin{tikzpicture} %
      \node[draw=#1!80, fill=#1!20, rounded corners=5pt, inner sep=11pt]{ % Add a little bit of transparency
        $\begin{array}{l} % One-cell table
           \includegraphics[#4]{{#2}} % Alert icon
         \end{array}$ %
         \settowidth{\alertmessage@textlength}{{#3}} %
         \ifthenelse{\lengthtest{\alertmessage@textlength > 400pt}}{ % If text is more than 400pt
           \parbox{340pt}{{#3}} % Box which handles paragraphs, limited to 10cm
         }{ % Else
           \makebox{}{{#3}} % Box which adapts itself to the text length
         } %
      }; %
    \end{tikzpicture} %
  \end{center} %
  \par % Get back the indentation
}%

\renewcommand*\alertsuccess[1]{%
  \alertmessage@panelcustom{green}{example-image-a}{#1}[width=6mm]%
}%

\makeatother

\begin{document}

\alertinfo{hello}
\alertwarning{hello}
\alertsuccess{hello}
\alerterror{hello}

\end{document}

编辑2 直接修补软件包的版本。上面的版本当然更简单,但这里是为了好玩:

\documentclass{article}
\usepackage{regexpatch}
\usepackage{graphicx}
\usepackage{alertmessage}

\makeatletter
% let's patch
\NewCommandCopy\originalalertmessage@panel\alertmessage@panel
\xpatchparametertext\originalalertmessage@panel{\#1\#2\#3}{\cP\#1\cP\#2\cP\#3\cP\#4}{}{}
\xpatchcmd{\originalalertmessage@panel}{\includegraphics[scale=0.5]}{\includegraphics[scale=0.5,#4]}{}{}


\RenewDocumentCommand{\alertmessage@panel}{mmmO{}}{%
  \originalalertmessage@panel{#1}{#2}{#3}{#4}%
}

\renewcommand*\alertsuccess[1]{%
  \alertmessage@panel{green}{example-image-a}{#1}[width=6mm]%
}%
\makeatother

\begin{document}


\alertinfo{hello}
\alertwarning{hello}
\alertsuccess{hello}
\alerterror{hello}

\end{document}

相关内容