latex3 / mathtools

Mathematical tools to use with amsmath
LaTeX Project Public License v1.3c
57 stars 7 forks source link

Declare custom formatted delimiters #47

Closed vepain closed 2 years ago

vepain commented 2 years ago

Hello everyone,

First I want to thank mathtools package maintainers.

Issue Description

The issue is about declaring paired delimiters with \DeclarePairedDelimiter(X): if I want to e.g. colour the delimiters (with defining a new command), the mathtools won't work.

MWE:

% ============================================================================ %
%                                   SETTINGS                                   %
% ============================================================================ %
\documentclass{article}

\usepackage{xcolor} % for \textcolor command
\usepackage{mathtools} % for \DeclarePairedDelimiterX command

% Formatted paired delimiter
%
%   - coloured delimiter definition
%
\newcommand{\absdelim}{\textcolor{red}{|}}
%
%   - declare the paired delimiter with mathtools
%
\DeclarePairedDelimiterX{\absval}[1]{\absdelim}{\absdelim}{#1}

% ============================================================================ %
%                                     BODY                                     %
% ============================================================================ %
\begin{document}

This does not work:
\[
    \absval*{\frac{\frac{a}{b}}{\frac{c}{d}}}
\]

This alone works:
\[
    \absdelim
\]

\end{document}

The compiler raises this: Missing delimiter (. inserted).

You can test with other custom commands: if the delimiter in the \newcommand{\absdelim} is formatted by another command, the compiler won't run.

Question

Is there a trick to format delimiters (perhaps using <post> \DeclarePairedDelimiterX's optional argument or by using \DeclarePairedDelimiterPPX command)?

Have a nice day!

this issue is a duplicate of this one: https://tex.stackexchange.com/questions/658942/declare-custom-formatting-delimiters-mathtools

daleif commented 2 years ago

AFAIK the coloring breaks \left etc as they cannot see the delimiter they need to act on. You problably need something similar to {\color{red}\abs*{\color{black} A\color{red}}} (untested), wrapped into a macro of course.

davidcarlisle commented 2 years ago

I just posted an answer at stackexchange basically same as @daleif's comment above which I now see, I suggest this is closed here I don't think this can be addressed in mathtools

vepain commented 2 years ago

Thank you all! I marked this answer as the correct one: https://tex.stackexchange.com/a/658946/232319 I close this issue