我致力于为大学编写我的课程,我们希望文章的第一部分以lettrine
包中的大写字母开头,标题为“介绍”。我必须将其放入课程中并为作者提供模板。我附上的示例有效,直到您没有在类定义命令\introduction
和文本之间以空行开头。
如何让\newcommand
最后一行的定义MyClass.cls
忽略不习惯或懒惰的作者留下的空行?
我附上了我必须使用的最少的工作示例(因此会有额外的功能)。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 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}
模板如下:
% !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}
答案1
\introduction
改变来自的定义
\newcommand{\introduction}{\section{Introduction}\label{intro}\ecap}
到
\newcommand{\introduction}{\section{Introduction}\label{intro}\ecappar}
并定义\ecappar
为
\newcommand\ecappar[1]{\ifx\par#1\def\next{\ecappar}\else\def\next{\ecap{#1}}\fi\next}
这里,\ecappar
吸收所有中间的\par
标记。当用完它们时,它会调用\ecap
下一个东西。
已编辑,使其\ecappar
更加强大。已重新编辑,使其适用于变音符号。
这是样式文件
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 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}
以及 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}