Use custom brackets
The \llceil
, \rrceil
, \llfloor
and \rrfloor
symbols of stmaryrd
are available at a single size.
You can define macros \dceil
and \dfloor
that take an argument; with \dceil*
automatically extensible delimiters are produced and a numeric optional argument adds some negative kern between the two \lceil
or \rceil
that are used. Without the *
, the optional argument can be \big
, \Big
, \bigg
or \Bigg
. The same for \dfloor
.
\documentclass{article}
\usepackage{amsmath,xparse,stmaryrd}
\ExplSyntaxOn
\NewDocumentCommand{\dceil}{sO{0}m}
{
\IfBooleanTF{#1}
{
\spiros_ceilfloor_ext:nnnn { #2 } { #3 } { \lceil } { \rceil }
}
{
\spiros_ceilfloor:nnnn { #2 } { #3 } { \lceil } { \rceil }
}
}
\NewDocumentCommand{\dfloor}{sO{0}m}
{
\IfBooleanTF{#1}
{
\spiros_ceilfloor_ext:nnnn { #2 } { #3 } { \lfloor } { \rfloor }
}
{
\spiros_ceilfloor:nnnn { #2 } { #3 } { \lfloor } { \rfloor }
}
}
\cs_new_protected:Npn \spiros_ceilfloor_ext:nnnn #1 #2 #3 #4
{
\left#3
\mkern-\muskip_eval:n { 4.5mu + #1mu }
\left#3
#2
\right#4
\mkern-\muskip_eval:n { 4.5mu + #1mu }
\right#4
}
\cs_new_protected:Npn \spiros_ceilfloor:nnnn #1 #2 #3 #4
{
\mathopen{\str_if_eq:nnF { #1 } { 0 } { #1 }#3}
\mkern\spiros_kern:n { #1 }
\mathopen{\str_if_eq:nnF { #1 } { 0 } { #1 }#3}
#2
\mathclose{\str_if_eq:nnF { #1 } { 0 } { #1 }#4}
\mkern\spiros_kern:n { #1 }
\mathclose{\str_if_eq:nnF { #1 } { 0 } { #1 }#4}
}
\cs_new:Npn \spiros_kern:n #1
{
\str_case:nnF { #1 }
{
{ \big }{ -4.5mu }
{ \Big }{ -5.5mu }
{ \bigg }{ -6.5mu }
{ \Bigg }{ -7.5mu }
}
{ -4.5mu }
}
\ExplSyntaxOff
\begin{document}
\[
\llceil x\rrceil\\
\dceil*{x} \quad
\dceil*{\frac{x}{2}}\quad
\dceil*[1]{\frac{x}{2}}\quad
\dceil*[3]{\frac{\dfrac{x}{2}}{\dfrac{y}{3}}}
\]
\[
\dceil{x}\quad
\dceil[\big]{x}\quad
\dceil[\Big]{x}\quad
\dceil[\bigg]{x}\quad
\dceil[\Bigg]{x}
\]
\[
\llfloor x\rrfloor\\
\dfloor*{x} \quad
\dfloor*{\frac{x}{2}}\quad
\dfloor*[1]{\frac{x}{2}}\quad
\dfloor*[3]{\frac{\dfrac{x}{2}}{\dfrac{y}{3}}}
\]
\[
\dfloor{x}\quad
\dfloor[\big]{x}\quad
\dfloor[\Big]{x}\quad
\dfloor[\bigg]{x}\quad
\dfloor[\Bigg]{x}
\]
\end{document}
The result seems acceptable without correction in the case of \dceil*
and \dfloor*
up to a certain size (corresponding to \bigg
); after it a correction is needed.
Maybe the correction could be made automatic based on the size of the mandatory argument.
It's not perfect, because the stretching of the glyph thickens up the horizontal stroke, but it may be sufficient for your needs. The \stretchleftright{}{}{}
macro will stretch arguments 1 and 3 to meet the vertical extent of argument 2.
A related answer is Defining scalable "white curly brackets" {| and |} (⦃ and ⦄)
\documentclass{article}
\usepackage{stmaryrd}
\usepackage{scalerel}
\begin{document}
\[
\llceil x\rrceil ~~~\llfloor y \rrfloor
\]
\[
\stretchleftright{\llceil}{\frac{x^2}{y_2}}{\rrceil}~~~
\stretchleftright{\llfloor}{\sqrt{y^2}}{\rrfloor}
\]
\end{document}
The other approach is to stick two of the normal "ceil"s together. This will avoid the thickening of the horizontal stroke, but it must be matched with another "double" glyph.
\documentclass{article}
\def\llceil{\left\lceil\kern-3.5pt\left\lceil}
\def\rrceil{\right\rceil\kern-3.5pt\right\rceil}
\begin{document}
\[
\llceil\frac{x^2}{y_2}\rrceil
\]
\end{document}