1

I am committed in writing my class for the university and we want the first section of the article to begin with capital from lettrine package and to be entitled "introduction". I must put this in the class and provide a template to the authors. The example I attach works until you don't start with an empty line between the class defined command \introduction and your text.

How to let the \newcommand defined in the last line in MyClass.cls ignore eventual blank lines left from an unaccustomed or lazy author?

I attach minimal working examples for what i must use (so there will be extra features).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% MyClass WORKING EXAMPLE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \NeedsTeXFormat{LaTeX2e}[1995/12/01] \ProvidesPackage{MyClass}[2017/08/30 v0.0] \AtEndOfClass{\RequirePackage{microtype}} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%MY CLASS doesn't support twocolumns %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \DeclareOption*{\PassOptionsToClass{\CurrentOption}{extarticle}} \ProcessOptions* \LoadClass[a4paper,11pt,final]{extarticle} %%%%%%%%%%%%%%%%%%%%%%% %%%%MUST-TO-BE INCLUDED PACKAGES %%%%%%%%%%%%%%%%%%%%%%% \RequirePackage[OT1, OT2, T1]{fontenc}%Font Encoding \RequirePackage[utf8]{inputenc}%UTF-8 Input Encoding (italian keyboard) \RequirePackage[polutonikogreek,italian,english]{babel}%Languages. Last one is the main one. \RequirePackage{authblk}%Affiliations \RequirePackage{amsfonts,amssymb,amsmath,amsthm,marvosym,wasysym,pxfonts,cancel}%All math symbols ever needed \RequirePackage{lipsum}%Dummy text i.e. \lipsum[3-5] \RequirePackage{xcolor}%Adding xcolors %%%%%%%%%%%%%%%%% %%Color scheme %%%%%%%%%%%%%%%%% \definecolor{color0}{RGB}{0,0,0} % Basic Black \definecolor{color1}{RGB}{59,90,198} % Author email %%%%%%%%%%%%%%%%%%% %%PAGE LAYOUT AND TITLEPAGE %%%%%%%%%%%%%%%%%%% \RequirePackage[left=80pt,% right=80pt,% top=70pt,% bottom=80pt,% headheight=15pt,% headsep=10pt,% a4paper,twoside]{geometry}% \RequirePackage[labelfont={bf,sf},% labelsep=period,% figurename=Fig.,% singlelinecheck=off,% justification=RaggedRight]{caption} \renewcommand{\@maketitle}{% \vskip60pt% {\raggedright \titlefont \@title\par}% \vskip12pt {\raggedright \@author\par} \rule{\linewidth}{.3pt} \vskip12pt% }% %%%%%%%%%%%%%%%%% %%NEWCOMMANDS %%%%%%%%%%%%%%%%% \newcommand{\titlefont}{\normalfont\sffamily\bfseries\fontsize{22}{25}\selectfont} \newcommand{\absfont}{\normalfont\rmfamily\bfseries\fontsize{11}{14}\selectfont} %%%%%%%%%%%%%%%%% %%Author/Affiliation Management %%%%%%%%%%%%%%%%% \setlength{\affilsep}{1em} \renewcommand\Authfont{\color{color0}\normalfont\sffamily\bfseries\scshape\fontsize{15}{17}\selectfont} %%%%%%%%%%%% %%%%FIRST LETTER %%%%%%%%%%%% \RequirePackage{ifthen} \RequirePackage{lettrine} \RequirePackage{yfonts} \DeclareFontShape{LYG}{ygoth}{m}{n}{ <-> ygoth}{} %\renewcommand{\LettrineTextFont}{\normalfont} \renewcommand{\LettrineFontHook}{\color[gray]{0.5}} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%By Reed A. Cartwright %%http://dererumnatura.us/archives/2009/02/automatic-usage.html %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \newcommand*{\ecap}[1]{\begingroup\obeyspaces\etospace{#1}{}} \newcommand*{\etospace}[3]{\ifthenelse{\equal{#3}{\space}}% {\endgroup\lettrine[lines=3, nindent=0em, findent=0.1em]{#1}{#2}#3}{\etospace{#1}{#2#3}}} % Setup environment `entry' to use `entry*' with a drop cap \newenvironment{entry}{\begin{entry*}\ecap}{\end{entry*}} % Setup environment `entry*' so that lettrine can be manually specified if needed \newenvironment{entry*}{}{} %%%%%%%%%%%%%%%% %%%CLASS DEFINITIONS %%%%%%%%%%%%%%%% \newcommand{\introduction}{\section{Introduction}\label{intro}\ecap} 

And here's the template:

% !TEX encoding = UTF-8 Unicode %%%%%%%%%%%%%%%%%%% %% WORKIN' EXAMPLE %%%%%%%%%%%%%%%%%%% \documentclass{MyClass} \begin{document} \date{} \setcounter{Maxaffil}{0} \renewcommand\Affilfont{\itshape\footnotesize} \title{Title of the publication} \author[a]{Giuseppe Verdi} \author[a, b]{Mario Rossi} \affil[a]{University A, address} \affil[b]{University B, address} \maketitle \begin{abstract} \lipsum[1] \end{abstract} \introduction %<==NO BLANK LINE AFTER THIS LINE!! HELP==> The beginning. \lipsum[2] \end{document} 
0

1 Answer 1

2

Change the definition of \introduction from

\newcommand{\introduction}{\section{Introduction}\label{intro}\ecap} 

to

\newcommand{\introduction}{\section{Introduction}\label{intro}\ecappar} 

and define \ecappar as

\newcommand\ecappar[1]{\ifx\par#1\def\next{\ecappar}\else\def\next{\ecap{#1}}\fi\next} 

Here, \ecappar absorbs all intervening \par tokens. When it runs out of them, it invokes \ecap on the next thing.

EDITED to make \ecappar more robust. RE-EDITED to make it work with diacritics.

Here is the style file

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% MyClass WORKING EXAMPLE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \NeedsTeXFormat{LaTeX2e}[1995/12/01] \ProvidesPackage{MyClass}[2017/08/30 v0.0] \AtEndOfClass{\RequirePackage{microtype}} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%MY CLASS doesn't support twocolumns %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \DeclareOption*{\PassOptionsToClass{\CurrentOption}{extarticle}} \ProcessOptions* \LoadClass[a4paper,11pt,final]{extarticle} %%%%%%%%%%%%%%%%%%%%%%% %%%%MUST-TO-BE INCLUDED PACKAGES %%%%%%%%%%%%%%%%%%%%%%% \RequirePackage[OT1, OT2, T1]{fontenc}%Font Encodingintroduction \RequirePackage[utf8]{inputenc}%UTF-8 Input Encoding (italian keyboard) \RequirePackage[polutonikogreek,italian,english]{babel}%Languages. Last one is the main one. \RequirePackage{authblk}%Affiliations \RequirePackage{amsfonts,amssymb,amsmath,amsthm,marvosym,wasysym,pxfonts,cancel}%All math symbols ever needed \RequirePackage{lipsum}%Dummy text i.e. \lipsum[3-5] \RequirePackage{xcolor}%Adding xcolors %%%%%%%%%%%%%%%%% %%Color scheme %%%%%%%%%%%%%%%%% \definecolor{color0}{RGB}{0,0,0} % Basic Black \definecolor{color1}{RGB}{59,90,198} % Author email %%%%%%%%%%%%%%%%%%% %%PAGE LAYOUT AND TITLEPAGE %%%%%%%%%%%%%%%%%%% \RequirePackage[left=80pt,% right=80pt,% top=70pt,% bottom=80pt,% headheight=15pt,% headsep=10pt,% a4paper,twoside]{geometry}% \RequirePackage[labelfont={bf,sf},% labelsep=period,% figurename=Fig.,% singlelinecheck=off,% justification=RaggedRight]{caption} \renewcommand{\@maketitle}{% \vskip60pt% {\raggedright \titlefont \@title\par}% \vskip12pt {\raggedright \@author\par} \rule{\linewidth}{.3pt} \vskip12pt% }% %%%%%%%%%%%%%%%%% %%NEWCOMMANDS %%%%%%%%%%%%%%%%% \newcommand{\titlefont}{\normalfont\sffamily\bfseries\fontsize{22}{25}\selectfont} \newcommand{\absfont}{\normalfont\rmfamily\bfseries\fontsize{11}{14}\selectfont} %%%%%%%%%%%%%%%%% %%Author/Affiliation Management %%%%%%%%%%%%%%%%% \setlength{\affilsep}{1em} \renewcommand\Authfont{\color{color0}\normalfont\sffamily\bfseries\scshape\fontsize{15}{17}\selectfont} %%%%%%%%%%%% %%%%FIRST LETTER %%%%%%%%%%%% \RequirePackage{ifthen} \RequirePackage{lettrine} \RequirePackage{yfonts} \DeclareFontShape{LYG}{ygoth}{m}{n}{ <-> ygoth}{} %\renewcommand{\LettrineTextFont}{\normalfont} \renewcommand{\LettrineFontHook}{\color[gray]{0.5}} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%By Reed A. Cartwright %%http://dererumnatura.us/archives/2009/02/automatic-usage.html %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \newcommand*{\ecap}[1]{\begingroup\obeyspaces\etospace{#1}{}} \newcommand\ecappar[1]{\ifx\par#1\def\next{\ecappar}\else\def\next{\ecap{#1}}\fi\next} \newcommand*{\etospace}[3]{\ifthenelse{\equal{#3}{\space}}% {\endgroup\lettrine[lines=3, nindent=0em, findent=0.1em]{#1}{#2}#3}{\etospace{#1}{#2#3}}} % Setup environment `entry' to use `entry*' with a drop cap \newenvironment{entry}{\begin{entry*}\ecap}{\end{entry*}} % Setup environment `entry*' so that lettrine can be manually specified if needed \newenvironment{entry*}{}{} %%%%%%%%%%%%%%%% %%%CLASS DEFINITIONS %%%%%%%%%%%%%%%% \newcommand{\introduction}{\section{Introduction}\label{intro}\ecappar} 

and the MWE:

% !TEX encoding = UTF-8 Unicode %%%%%%%%%%%%%%%%%%% %% WORKIN' EXAMPLE %%%%%%%%%%%%%%%%%%% \documentclass{MyClass} \begin{document} \date{} \setcounter{Maxaffil}{0} \renewcommand\Affilfont{\itshape\footnotesize} \title{Title of the publication} \author[a]{Giuseppe Verdi} \author[a, b]{Mario Rossi} \affil[a]{University A, address} \affil[b]{University B, address} \maketitle \begin{abstract} \lipsum[1] \end{abstract} \introduction %<==NO BLANK LINE AFTER THIS LINE!! HELP==> The beginning. \lipsum[2] \introduction %<==NO BLANK LINE AFTER THIS LINE!! HELP==> The beginning. \lipsum[2] \introduction %<==NO BLANK LINE AFTER THIS LINE!! HELP==> \par\par The beginning. \lipsum[2] \end{document} 

enter image description here

6
  • That was quick and painless! i found a new family... thank you a lot. Commented Aug 30, 2017 at 11:04
  • @P.Oliva I made a slight redefinition of \ecappar to make it more robust. Please use this revised version. Commented Aug 30, 2017 at 11:05
  • @P.Oliva I note that it does not work if the first letter of the introduction is umlauted, for example \"A. I don't know if that problem is from my definition, yours, or an intrinsic limitation of lettrine. Just sayin'. Commented Aug 30, 2017 at 11:11
  • Ok! thank you. The aumlaut prob is not at all critical for the use i have in mind but still can be studied for the sake of understanding. And i bet it is a non compatibility of lettrine package. I'll let you know if i find out. Commented Aug 30, 2017 at 11:14
  • @P.Oliva Found and fixed the problem. I needed an extra group around the use of #1 in the definition of \ecappar. Commented Aug 30, 2017 at 11:24

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.