# Need help to construct an environment

I am typesetting a document, and I am trying to convert a command into a environment. Here is the original code and the first environment (which actually works).

\newcommand{\crub}[1]{%
\begin{center}
\textcolor{red}{\textbf{\small #1}}%
\end{center}
}

\newenvironment{crub}{   % new environment instead of command
\begin{trivlist}
\centering
\bfseries
\color{red}
\item\relax
}{\end{trivlist}}


Now, here is the code for the command that I cannot seem to get into a proper environment.

\newcommand{\psalmheading}[1]{%
\begin{center}
\noindent\textcolor{red}{\textbf{\large #1}}%
\end{center}
}


To explain further, here is a part of the original doc, BEFORE I tried to change commands into environments:

%Beginning of the Preamble % % % % % % % % % % % % % % % % % % % %

%Document Class and Packages to use % % % % % % % % % % % % % % % %
\documentclass[12pt,letterpaper,twoside]{book}
\usepackage[left=2.05cm,right=2.10cm,top=2.45cm,bottom=2.5cm]{geometry}
\usepackage{amsmath,amssymb,color,fancyhdr,framed,titlesec}

\pagestyle{fancy}
\setcounter{chapter}{-1}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}{}}
\cfoot{\thepage}

%Shortcut Commands % % % % % % % % % % % % % % % % % % % % % % % %
\newcommand\stich[1]{%
\textcolor{red}{S.  }#1%
}

\newcommand\response[1]{%
\textcolor{red}{R.  }#1%
}

\begin{center}
\noindent\textcolor{red}{\textbf{\large #1}}%
\end{center}
}

\begin{center}
\noindent\textcolor{black}{\textbf{\large #1}}%
\end{center}
}

\begin{center}
\noindent\textcolor{black}{\textbf{\large #1}}%
\end{center}
}

\begin{center}
\noindent\normalsize\textcolor{red}{#1}
\end{center}
}

\newcommand{\rub}[1]{%
\textcolor{red}{\textbf{\small #1}}%
}

\newcommand{\brub}[1]{%
\textcolor{black}{\textbf{\small #1}}%
}

\newcommand{\crub}[1]{%
\begin{center}
\textcolor{red}{\textbf{\small #1}}%
\end{center}
}

\newcommand{\cbrub}[1]{%
\begin{center}
\textcolor{red}{\textbf{\small #1}}%
}

%Formatting to Center the Chapter, Section, and Subsection Titles %
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries\centering}{}{20pt}{\Huge}
\titlespacing*{\chapter}
{0pt}{50pt}{40pt}

\titleformat{\section}
{\normalfont\Large\bfseries\centering}{}{1em}{}
\titlespacing*{\section}
{0pt}{3.5ex plus 1.0ex minus 0.2ex}{2.3ex plus 0.2ex}

\titleformat{\subsection}
{\normalfont\large\bfseries\centering}{}{1em}{}
\titlespacing*{\subsection}
{0pt}{3.25ex plus 1.0ex minus 0.2ex}{1.5ex plus 0.2ex}
%End of the Preamble % % % % % % % % % % % % % % % % % % % % % % %

%Title Info % % % % % % % % % % % % % % % % % % % % % % % % % % % %
\title{AN ORTHODOX RULE OF PRAYER.}
\author{Father Thomas Moore, Michael Dykes}
\date{\today}
\begin{document}
\maketitle
\tableofcontents

\part{SUNDAY PRAYERS.}
\chapter{SATURDAY EVENING PRAYERS.}
\crub{Towards evening, we stand before the holy icons (having lit a candle     and maybe some incense), with reverence and fear of God; we gather our thoughts, make the Sign of the Cross, and say:}

In the Name of the Father, and of the Son, and of the Holy Spirit. Amen.

\begin{framed}
\crub{From St. Thomas Sunday until Ascension, instead of \textbf{O God,  cleanse me, a sinner \ldots we say:}}
\textrm{Christ is risen from the dead, trampling down death by death, and  upon those in the tombs bestowing life. \crub{(thrice)}}

\crub{During any Vigil-rank Festal Period [(see Appendix A) - including your and your Temple's Patronal Feast Day], we begin our prayers by praying the Festal Troparia (again, see Appendix A).}

\crub{Then, in either case, we immediately pray the Trisagion Prayers as below:}
\end{framed}

\crub{Afterwards, we collect our thoughts, and make seven prostrations (or metanoias), saying:}

\section{THE SEVEN--BOW BEGINNING.}
O God, be merciful to me, a sinner.

O God, cleanse me, a sinner, and have mercy on me.

Thou hast created me, O Lord, have mercy on me.

Countless times have I sinned, O Lord, forgive me.

All-holy Lady Theotokos, save me, a sinner,

O Angel, my holy Guardian, protect me from all evil.

O Saint, \crub{N}, my Patron pray to God for me.

\crub{Then, we begin the Evening Prayers with these words:}

\section{THE INTRODUCTORY PRAYERS.}
O Lord Jesus Christ our God, through the prayers of our Thine All-pure Mother, of our holy and God-bearing Fathers, and of all the saints, have mercy on us. Amen.

Glory to Thee, O our God, Glory to Thee.

O Heavenly King, the Comforter, the Spirit of Truth, Who art everywhere present and fillest all things, Treasury of blessings and Giver of Life: Come and abide in us; and cleanse us from every impurity, and save our souls, O Good One.

\section{TRISAGION PRAYERS.}
Holy God. Holy Mighty. Holy Immortal. Have mercy on us. \crub{(thrice)}

\end{document}


Upon compiling, I see the section and chapter headings, then to the left of thes, I see a 'shadowed' section and chapter heading. That is what I was trying to get rid of. Thanks again, because at this point, I am a bit lost.

-
What's the point? The two commands do exactly the same (apart from \large instead of \small). –  egreg Jan 25 '12 at 21:33
The first obviously cannot work, because the crub environment does not contain \small, whereas the command \crub contains it. And another thing: Never use the same name on both a command and an environment, because it creates a macro name clash. –  tohecz Jan 25 '12 at 21:42
I may not be fully understanding you (or maybe I was not really clear when asking my question), but I do not have both the crub command and the crub environment in the same doc. Due to other issues (which are solved by using the environment), I am using that instead of the the command. I am foregoing the /small there. Additionally, I wish to convert the /psalmheading to environment form, if possible. Thanks. Oh, sorry the second block of code was what I was trying to do to convert the \psalmheading to an environment form. –  Michael Dykes Jan 25 '12 at 21:47
Just to give you an idea of what is going on, here is part of my doc (the original): –  Michael Dykes Jan 25 '12 at 21:53

There are unnecessary bits in your definition of the crub environment:

\newenvironment{crub}
{\begin{center}\color{red}\bfseries\small}
{\end{center}}


is simpler. Actually center is defined with trivlist, but it's better to stick with higher level objects as long as it is possible.

The same strategy works with psalmheading:

\newenvironment{psalmheading}
{\begin{center}\color{red}\bfseries\large}
{\end{center}}


You probably had a problem caused by \noindent which starts LR mode so that you got a spurious space in the output; but in center the indent is zero anyway.

-
One more major question (if I may). Currently, the header is set to the chapter (left header) and the section (right header) which I would like to keep, but in some cases they are overlapping. I need a way for both of them to be lowercase and not ALL CAPS, but am not sure how to do this??? –  Michael Dykes Jan 25 '12 at 22:13
Try to put \let\MakeUppercase\relax in your preamble. This will prevent LaTeX from uppercasing the marks (instead of "making uppercase", the LateX will just "relax for a while". –  tohecz Jan 25 '12 at 22:19
@MichaelDykes Look at the packages fancyhdr or titleps for a way to customize your headers. –  egreg Jan 25 '12 at 22:21
@tohecz When I tried adding \let\MakeUppercase\relax to my preamble, I ended up with several blank sheets at the beginning of the doc??? –  Michael Dykes Jan 26 '12 at 0:26
@MichaelDykes It's not a good idea to redefine an important command of LaTeX. The approach with fancyhdr is recommended. The manual is quite clear. –  egreg Jan 26 '12 at 0:28

I hope this is a solution (it defines the environment psalmheading, just using the TeX primitives, I prefer it this way):

\usepackage{xcolor}


Using the more standard LaTeX commands should be the same:

\usepackage{xcolor}
\newenvironment{psalmheading}{% percent-sign and the end of line to remove spaces
\center\large\bfseries\color{red}%
}{\endcenter}


\endcenter is the ending command of \center. You are used to put \begin{center}...\end{center}, but \center...\endcenter runs a bit faster (and there're few more technical differences).

And you can use any formatting commands in the place of \large\bfseries\color{red}.

Full test code:

\documentclass{article}

\usepackage{xcolor}

\usepackage{lipsum} % package to add some dummy text

\begin{document}

\lipsum[1] % inputs some random text

\lipsum[2] % inputs some random text

\lipsum[3] % inputs some random text

\end{document}


Edit: the rub environment, the most tricky is removal of the next empty line, if there is any:

\documentclass{article}

\usepackage{lipsum}
\usepackage{xcolor}

\makeatletter
% got from http://phaseportrait.blogspot.com/2011/08/using-gobblepars-to-prevent-latex-from.html
\newcommand\gobblepars{%
\@ifnextchar\par%
{\expandafter\gobblepars\@gobble}%
{}}
\def\aftergobblepars{\expandafter\gobblepars}
\makeatother

\newenvironment{rub}{%
\small\bfseries\color{red}%
}{%
\quad % put any space command here
\aftergroup\aftergobblepars\gobblepars%
}

\begin{document}

\lipsum[1]

\begin{rub}
LABEL
\end{rub}

\lipsum[4]

\end{document}

-
@tohecx So, what does the command /lipsum do exactly? Also, could this format be applied to all my other /newcommands (see above)? Thanks again. I am really loving LaTeX and TeX, the more I learn about it. –  Michael Dykes Jan 25 '12 at 22:07
Sorry, I should have explained better. I added comments to my response. –  tohecz Jan 25 '12 at 22:18
@MichaelDykes: \lipsum just generates text, so you don't have to type some random text yourself. –  celtschk Jan 25 '12 at 22:23
Why \begingroup and \endgroup? They are added automatically by \begin and \end. Moreover \noindent serves no purpose. Moreover it's preferable to stick with "standard" LaTeX commands, instead of \def, whenever possible: a beginner might be confused with the syntax. –  egreg Jan 25 '12 at 23:19
@egreg: \noindent shall be omitted, you are right, edited. The grouping is a matter of habits, I often use such commands in the short syntax (\env...\endenv) hence the grouping... so again you are right. –  tohecz Jan 25 '12 at 23:23