# how to write ceil and floor in latex?

Is there a macro in latex to write ceil(x) and floor(x) in short form? The long form

\left \lceil{x}\right \rceil


is a bit lengthy to type every time it is used.

-

## migrated from stackoverflow.comJun 7 '13 at 22:41

This question came from our site for professional and enthusiast programmers.

Welcome to TeX.SX! Your post was migrated here from another Stack Exchange site. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. –  Joseph Wright Jun 8 '13 at 5:31
Thank you, it seems I was asking questions in the wrong forum indeed! –  danny Jul 7 '13 at 17:35

Using \DeclarePairedDelimiter from mathtools, you could define macros \ceil and \floor, which will scale the delimiters properly (if starred):

\documentclass{minimal}
\usepackage{mathtools}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}

\begin{document}
\begin{equation*}
\floor*{\frac{x}{2}} < \frac{x}{2} < \ceil*{\frac{x}{2}}
\end{equation*}
\end{document}


Result:

-
1. You can define your own macro via the \def command anywhere in your document. For example

\def\lc{\left\lceil}
\def\rc{\right\rceil}


and then just write \lc x \rc.

2. Or you use the \providecommand in the preamble, e.g.

\providecommand{\myceil}[1]{\left \lceil #1 \right \rceil }


to simply use \myceil{x} in your document.

3. Use an editor, like vim, that allows for defining shortcuts for quick and efficient editing.