Q:

Different chapters, different layout

On request, I have two different layouts for chapters for a book. The first one is exclusive to the Chapter 1 and the other one is for the others. The layout affect how the sections, definitions and paragraphs are displayed. I have the code to handle this in a little class file. This is a MWE:
\documentclass[12pt,letterpaper]{book}

\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{thmtools}
\usepackage{ifthen,calc}
\usepackage{blindtext}

\parindent=0mm

\newtheorem{teo}{Theorem}[section]
\newtheorem{axi}{Axiom}
\newtheorem{lem}{Lemma}

\newcounter{definition}
\declaretheoremstyle[%
  spaceabove=6pt,%
  spacebelow=6pt,%
  headfont=\normalfont\bf,%
  notefont=\normalfont\bf,
  notebraces={{}{}},
  bodyfont=\itshape,
  headpunct={.}]{defistyle} 
\declaretheorem[
    name={Definition},
    numberlike=definition,
    style=defistyle]{defi}

\renewcommand\thesection
    {\arabic{chapter}.\arabic{section}}
\makeatletter
\renewcommand\@seccntformat[1]{
    {\csname the#1\endcsname}.\hspace{0.5em}}
\renewcommand\section{\@startsection
    {section}{1}{0mm}                
    {6pt}                            
    {1pt}                            
    {\bfseries}}                     

\renewcommand\paragraph{\@startsection
    {paragraph}{3}{0cm}             
    {6pt}                           
    {1pt}                           
    {\bfseries}}                    
\makeatother

\makeatletter
\newcommand{\capi}[1]{
    \chapter{#1}
    \ifthenelse{\value{chapter}=2}{
        \renewcommand\section{\@startsection
        {section}{1}{0mm}               
        {0pt}                           
        {1pt}                           
        {\Large}}                       
        \@addtoreset{definition}{section}
        \renewcommand{\thedefi}{\thesection.\arabic{definition}}        
        }{}}
\makeatother

\begin{document}
\capi{Some preliminaries}
\blindtext

\section{the first thing}
\blindtext[1]

\begin{defi}
The thing $1$ is real number. If $x$ is real then $x+1$ is real.
\end{defi}

\blindtext

\capi{Cool stuff}
\blindtext

\section{Complex things}
bla bla bla

\begin{defi}
We say that a number $x$ is complex if it is not really a number.
\end{defi}

\blindtext
\end{document}

As you can see, my actual way to handle the different style for each chapter is not so elegant. I have the book splitted in several files, one per chapter. When I'm reviewing the book I'm select the chapters I want to see via the \includeonly command. The problem is that in order to get the proper look of the sections, paragraphs and definitions I always have to include the chapter 2. Also, I'll would like to avoid to define a new command to the chapters.  My question is: is there a way to improve this? 

A:

Just define \capi to redefine itself when it's not the first chapter, so that the test and the redefinition will be performed only once.
\makeatletter
\newcommand{\capi}{%
  \ifnum\value{chapter}>0
    \changesectionanddefi
    \let\capi\chapter
  \fi
    \chapter
}
\def\changesectionanddefi{%
   \renewcommand\section{\@startsection{section}{1}{0mm}{6pt}{1pt}{\Large}}%
   \@addtoreset{definition}{section}%
   \renewcommand{\thedefi}{\thesection.\arabic{definition}}%
}
\makeatother

You can even do better: redefine \chapter so as to get rid of the non standard \capi command:
\makeatletter
\let\leo@chapter\chapter
\renewcommand{\chapter}{
  \ifnum\value{chapter}>0 
    \changesectionanddefi 
    \let\chapter\leo@chapter
  \fi
    \leo@chapter
}
\def\changesectionanddefi{%
   \renewcommand\section{\@startsection{section}{1}{0mm}{6pt}{1pt}{\Large}}%
   \@addtoreset{definition}{section}%
   \renewcommand{\thedefi}{\thesection.\arabic{definition}}%
}
\makeatother

So, no \capi with this, but the usual \chapter.

Be careful with end-of-lines in definitions. Also check the parameters to \@startsection: your code was not working correctly.

A:

Your problem is that you use a suboptimal condition.  The condition is not that the chapter counter is equal to 2 but that the counter is greater than 1. Then the condition holds for all sections in all chapters. Thus you can then define \section to change its layout depending on the condition instead of placing the redefinition of \section inside the \chapter command.
Downside: the test will be executed whenever a section is processed (rather than only during chapter 2 once) but that is will not make a noticable difference in processing time.

