# Spacing for unusual brackets

I'm pretty new to LaTeX and have no idea about it's inner workings, but I would like to typeset an expression with double-stroke brackets. I found such a symbol (\llbracket and \rrbracket) in the stmaryrd package, but it doesn't seem to give good spacing towards the sides. I tried two things (imitating some answers to similar question for the second variant), but it doesn't seem to work.

\documentclass{article}
\usepackage{amsmath}
\usepackage{stmaryrd}

\newcommand{\repA}[1]{\left\llbracket #1 \right\rrbracket}
\newcommand{\repB}[1]{\left\llbracket\! #1 \,\right\rrbracket}

\begin{document}
\Large
\begin{align*}
\repA{\vec{v}}\\
\repB{\vec{v}}
\end{align*}
\end{document}


I'm not sure how to upload images here, in any case the symbol inside is too close to the right bracket for the first version and too close to the left bracket for the second. What is the correct way to define a command that takes care of spacing and does it right? Thank you very much in advance.

The problem is with \vec, which produces an arrow that can extend to the right of the glyph underneath.

Here I propose a redefinition that adds some amount of space after the \vec construction, based on the difference with the width of “w”.

I also use \DeclarePairedDelimiter that offers an easy way to adjust the size of the delimiters.

\documentclass{article}
\usepackage{amsmath,mathtools}
\usepackage{stmaryrd}

\DeclarePairedDelimiter{\rep}{\llbracket}{\rrbracket}
\makeatletter
\AtBeginDocument{%
\let\latex@vec\vec
\renewcommand\vec[1]{{\latex@vec{#1}\mathpalette\@vec{#1}}}%
}
\newcommand\@vec[2]{%
\sbox\z@{$\m@th#1w$}%
\sbox\tw@{$\m@th#1#2$}%
\ifdim\wd\tw@<\wd\z@
\kern0.2\dimexpr\wd\z@-\wd\tw@\relax
\fi
}
\makeatother

\begin{document}
\begin{gather*}
\vec{v}+\vec{w}\\
\rep{\vec{x}}+\rep{\vec{v}}+\rep{\vec{w}}\\
\rep{\vec{v}}+\rep[\big]{\vec{v}}+
\rep[\Big]{\vec{v}}+\rep*{\frac{1}{2}\vec{v}}
\end{gather*}
\end{document}


Ultimately it comes down to whoever designed the font metrics. With stmaryrd I'd agree that it looks rather off-centre with the italic slope, I'd probably just use \, on the right

\newcommand{\repC}[1]{\llbracket#1\,\rrbracket}


producing the top version below. Although you can use smaller adjustments if needed. \, is \thinmuskip which is 3mu by default so \mkern2mu is smaller...

But other fonts give different spacing, if you use

\usepackage{stix}


to use the stix fonts then

\newcommand{\repD}[1]{\lBrack#1\rBrack}


produces the lower version, which perhaps needs no adjustment in the tex macros.

You can have a macro with a correct spacing with mathtools and its \DeclareMathDelimiterX command. You obtain a macro which has an implicit pair of \left … \togt in its starred version, or can use an optional argument (\big, \Big, &c.) for fine-tuning of the delimiter size. I also suggest you use the \vv command, from esvect, which has nicer arrow tips than \vec (8 kinds of tips!):

\documentclass{article}
\usepackage{mathtools}
\usepackage{stmaryrd}
\usepackage[b]{esvect}

\DeclarePairedDelimiterX\repC[1]\llbracket\rrbracket{#1\mkern1.2mu}

\begin{document}
\Large
\begin{gather*}
\end{gather*}

\end{document}


You can use the the fdsymbol package:

\documentclass{article}
\usepackage{fdsymbol}
\usepackage{amsmath}
\begin{document}
\Huge
$\lBrack\vec{v}\rBrack$
\end{document}


This yields: