Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

i used this code but there is an error:

! Use of \@ doesn't match its definition.

I'm trying to make my book such as:

‎\documentclass[a4paper,14pt,twoside]{tufte-book}‎
\usepackage{amsthm,amssymb,amsmath}‎

‎\usepackage{graphicx‎ ,‎xcolor‎ ,‎mdframed}‎
‎‎\usepackage[version=0.96]{pgf}‎

%‎\input{mystyle}‎
‎
\setcounter{secnumdepth}{3}
‎\usepackage{color‎}‎
‎\def\chpcolor{blue!45}‎
‎\def\chpcolortxt{blue!60}‎

%Section: ---------------------------------------------------------------------------------
‎\def\@makesectionhead#1{‎ 
‎   { \vspace{20pt}‎
‎   \parindent 0pt \raggedleft \sectionfont‎ 
    \colorbox{\chpcolor} { \parbox[c][17pt][c]{90pt}{\color{white} \hfill \thesection‎ }}
‎   \hspace*{5pt}‎
‎   \vspace{10pt}‎
‎   \begin{minipage}[c][17pt][c]{\textwidth}‎
    ‎   \color{\chpcolortxt} #1‎
‎   \end{minipage}‎
‎   }‎
 }
‎\def\section{\@afterindentfalse \secdef\@section\@ssection}‎
‎\def\@section[#1]#2{\ifnum \c@secnumdepth >\m@ne‎
 ‎\refstepcounter{section}‎
 ‎\addcontentsline{toc}{section}{\protect‎
 ‎\numberline{\thesection}#1}\else‎
 ‎\addcontentsline{toc}{section}{#1}\fi‎
 ‎\sectionmark{#1}‎
 ‎\if@twocolumn\@topnewpage[\@makesectionhead{#2}]‎
 ‎\else \@makesectionhead{#2}\@afterheading \fi}‎
\def\@ssection#1{\if@twocolumn \@topnewpage[\@makesectionhead{#1}]‎
    ‎\else \@makesectionhead{#1}\@afterheading\fi}‎


‎

‎\begin{document}‎
‎‎\chapter{chapter}‎‏‎
This ‎is ‎test.‎
‎‎\section{section}‎‎
This ‎is ‎test.‎
‎\end{document}‎
share|improve this question
2  
Welcome to TeX.SE. There seem to be some extra characters in this file that won't let me compile your code. –  Peter Grill Nov 17 '12 at 6:12
    
What Should I Do? –  mohammad azadi Nov 17 '12 at 7:16
    
Sorry, wish I could help, but I don't know why those characters are there, and compiling gets stuck on \documentclass. If I retype the \documentclass line, then the problem moves to the next line. There was a recent question where a similar problem existed: LaTeX Error: Missing \begin{document}. Have a look at that and see if that helps you with these characters. –  Peter Grill Nov 17 '12 at 7:19
    
When i remove this lines: %Section: ---------\def\@makesectionhead#1{‎ ... \fi}‎ compile successfully. but i want to change color and style of chapters and sections and ..., can you help me? –  mohammad azadi Nov 17 '12 at 7:30
    
Try rewriting this with another editor which does not add invisible characters. –  Vafa Nov 17 '12 at 8:18
add comment

1 Answer

up vote 6 down vote accepted

After removing all the invisible characters from your input, there are still some problems. For instance, in order to use commands with @ in their name, you have to surround the code with \makeatletter and \makeatother.

I have tried to correct the small problems of your code; here is a version with only the needed packages. I tried to guess the meaning of \sectionfont.

\documentclass[a4paper,twoside]{tufte-book}

\usepackage{xcolor}

\def\chpcolor{blue!45}
\def\chpcolortxt{blue!60}
\def\sectionfont{\sffamily\LARGE}

\setcounter{secnumdepth}{2}

\makeatletter
%Section:
\def\@sectionstrut{\vrule\@width\z@\@height12.5\p@}
\def\@makesectionhead#1{%
  {\par\vspace{20pt}%
   \parindent 0pt\raggedleft\sectionfont
   \colorbox{\chpcolor}{%
     \parbox[t]{90pt}{\color{white}\@sectionstrut\@depth4.5\p@\hfill
       \ifnum\c@secnumdepth>\z@\thesection\fi}%
   }%
   \begin{minipage}[t]{\dimexpr\textwidth-90pt-2\fboxsep\relax}
   \color{\chpcolortxt}\@sectionstrut\hspace{5pt}#1
   \end{minipage}\par
   \vspace{10pt}%
  }
}
\def\section{\@afterindentfalse\secdef\@section\@ssection}
\def\@section[#1]#2{%
  \ifnum\c@secnumdepth>\m@ne
    \refstepcounter{section}%
    \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}%
  \else
    \phantomsection
    \addcontentsline{toc}{section}{#1}%
  \fi
  \sectionmark{#1}%
  \if@twocolumn
    \@topnewpage[\@makesectionhead{#2}]%
  \else
    \@makesectionhead{#2}\@afterheading
  \fi
}
\def\@ssection#1{%
  \if@twocolumn
    \@topnewpage[\@makesectionhead{#1}]%
  \else
    \@makesectionhead{#1}\@afterheading
  \fi
}
\makeatother

\begin{document}
\chapter{Chapter title}
This is a test.

\section{The Laplace transform}
This is a test.

\end{document}

enter image description here

share|improve this answer
    
Thank you. This is very good. –  mohammad azadi Nov 18 '12 at 5:14
    
How to change chapter style same as section? –  mohammad azadi Nov 19 '12 at 13:35
    
@mohammadazadi see the related follow-up question: tex.stackexchange.com/questions/96090/… –  cmhughes Jan 31 '13 at 16:30
    
If I'm writing an article the section style can work? I've tried it but I couldn't manage it! –  giannis Apr 9 '13 at 21:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.