Tag Info

Hot answers tagged

169

A bit of background first. When Knuth wrote TeX, he realised that most macros would not need to absorb more than one paragraph as an argument. As a result, a good way to test for errors such as a missing } is to forbid macros to accept paragraph tokens (either those generated by blank lines or explicit \par tokens). So he created \def for definitions which ...


47

See this entry in the UK TeX FAQ. The "elegant" way is to use the suffix package (which requires eTeX): \documentclass{article} \usepackage{suffix} \newcommand\foo{blah} \WithSuffix\newcommand\foo*{blahblah} \begin{document} \foo \foo* \end{document}


38

LaTeX3 solution: \documentclass{article} \usepackage{xparse} \NewDocumentCommand\foo{s}{% \IfBooleanTF#1% {blahblah}% If a star is seen {blah}% If no star is seen }


35

If you look at source2e you might see a lot of lines that look like \def\foo{\@ifstar\@foo\@@foo} \def\@foo#1{...} \def\@@foo#1{...} This makes \foo a one-argument command that has regular and starred versions. The starred version is the expansion of \@foo while the nonstarred version is that of \@@foo. Using the @ sign in the auxiliary macros is a TeX ...


35

According to the Companion: [\newcommand*] defines a [command], that is not, in TeX terms, long. This means that the newly defined command does not accept empty lines or \par. This is also the default behaviour of \def, while the unstarred version is actually equivalent to \long\def.


33

From the TUG faq: use the starred versions figure* and table*. Unfortunately, they're somewhat limited in positioning. Also, the same solution applies to equations. Just include them in a figure* environment. But I don't recommend doing this: it will look ugly and confusing. For an example, see this paper. (sorry, I couldn't find an example in arXiv)


33

To get unnumbered chapters, parts, sections, subsections, etc, you just affix a * (asterisk) to the respective sectioning command; hence, you'd type something like \section*{Acknowledgments} or \chapter*{Introduction} Exactly which sectioning command you ought to use will depend importantly on aspects of the document that you haven't told us about. ...


27

The \\ command is one of the most overloaded commands of LaTeX, i.e., its actual definition depends on the place where it is used. According to the the LaTeX manual by Leslie Lamport (which should be considered the source of truth here) its general definition is \\ produce an explicit line break (or indicate the end of a row etc) \\* produce line ...


24

Delay the closing of the group: after _, one can use \bgroup. \documentclass{article} \makeatletter \newcommand\dH{\bgroup d_H\@ifstar{^*\egroup}{\egroup}} \makeatother \begin{document} $B_\dH$ and $B_\dH*$ \end{document} But avoid it.


23

Write \setcounter{secnumdepth}{1} in your preamble. This says to LaTeX that only first level sections should be numbered; \subsection is level 2. As Gonzalo Medina points out, there's also the tocdepth counter that controls what section levels are included in the table of contents. LaTeX is happy to include also unnumbered section levels in the ToC, it's ...


21

As far as I know there are no such guidelines. As the author (and user) of a macro, you can decide how to use the starred version. But for a little consistency I’d use the star as mark for not numbered if the macro does something with numbering (as in your example). Otherwise I’d prefer to use the non starred version as default (often used) and the starred ...


21

I recommend to create a new macro with a different name instead of changing the behaviour of \section* and thus redefining \section. A separate macro would be a cleaner solution. The main LaTeX command for sectioning is \@startsection. It is documented in source2e.pdf, just type texdoc source2e at the command prompt. You would find it in 61.2 Sectioning. ...


20

Why do we give commands names? To indicate, ideally as clearly as possible, what it is that they do. If you have two things that do very similar things, it makes sense to give them very similar names. On the other hand, if they do one thing significantly differently, you would like to be able to easily tell the two names apart, despite those names being ...


19

Since the \newenvironment command uses a \csname, you can define it directly. \documentclass{article} \newenvironment{test*} {start}{end} \begin{document} \begin{test*} hello \end{test*} \end{document} You can have any combination of characters (with catcode 11 and 12) as you would in a \csname...\endcsname construct, \documentclass{article} ...


19

Spaces (glues and kerns) disappear after line breaks by rule; by the same rule, line breaks can happen only at the "left edge" of a space. Moreover, if one says \hspace{1cm}\hspace{1cm}, the first \hspace is a feasible break point, but not the second one. This is how TeX attains alignment to the left margin for normal and ragged right paragraphs (ragged ...


17

No they don't: \documentclass{article} \usepackage{suffix,xparse}% http://ctan.org/pkg/{suffix,xparse} \makeatletter \newcommand{\mycmdA}{\@ifstar \mycmdA@star% \mycmd* \mycmdA@nostar% \mycmd } \newcommand{\mycmdA@star}{A1} \newcommand{\mycmdA@nostar}{A2} \NewDocumentCommand{\mycmdB}{s}{% B\IfBooleanTF{#1}{1}{2}} \newcommand{\mycmdC}{C1} ...


15

It depends how you redefine the command. At the TeX level there is no such thing as a starred variant the base command just looks ahead for a star and acts accordingly. So if you redefine it such that it still looks ahead for the star then it will do so, otherwise it won't. Alternatvely you can save the old command of course. Here the \section commands ...


14

Why? questions can not really be answered except by the person who originally designed the system. But in most languages (certainly most languages of the era) the grammar for names of a language is defined by explicitly listing the allowed characters rather then listing terminating characters. In c or fortran or most other programming languages abc+xyz*rst ...


14

The relation is the same as that between \newcommand and \newcommand*, which is covered in What's the difference between \newcommand and \newcommand*? There's no influence on the environment's behavior, except as regards to the arguments to \begin{envname}. Specifically, if you say \newenvironment{foo}[1] {something with #1} {something else} ...


14

(I just learned about this recently:) This can be solved by loading the stfloats package and specifying a figure placement of [bp] as usual. (The p should always be included in case the bottom placement can never be achieved.)


14

The star at the end of the name of a displayed math environment causes that the formula lines won't be numbered. Otherwise they would automatically get a number. You can read about that in the amsmath user's guide since align belongs to amsmath. Such information can usually be found in the package documentation. Type texdoc packagename at the command ...


14

* cannot be used for the name of a control sequence. You must use the \csname...\endcsname pair here : \newenvironment{mequation}{\csname align*\endcsname}{\csname endalign*\endcsname}


13

You can use the starred version of \section, \section*, to produced a non-numbered section as in the following example: \documentclass{report} \begin{document} \section*{Acknowledgement}% This section is not numbered \chapter{Chapter name} \section{Section name}% This section is numbered \end{document} If you want to add the starred section to the table ...


13

Here's a simple solution using the ulem package and the explicit option for titlesec: \documentclass{scrartcl} \usepackage[explicit]{titlesec} \usepackage[normalem]{ulem} \usepackage{lipsum} \titleformat{\section} {\normalfont\Large\sffamily\bfseries\filcenter}{\uline{\thesection\hspace*{ 1em}}}{0em}{\uline{\MakeUppercase{#1}}} ...


13

Building on Gonzalo's answer: Use the numberless key to define the starred version of \section. \documentclass{scrartcl} \usepackage[explicit]{titlesec} \usepackage[normalem]{ulem} \usepackage{lipsum} \titleformat{\section} {\normalfont\Large\sffamily\bfseries\filcenter}{}{0em}{\uline{\thesection\hspace*{ 1em}\MakeUppercase{#1}}} ...


13

From here: "Using the starred version of \newcommand means that the arguments of the defined command cannot contain a blank line or \par. This makes it a lot easier to spot runaway arguments."


13

Mmm, \section* is simply easier to write than \sectionnotnumbered. Note that there aren't actual two macros defined, \section simply checks if a stars follows or not and branches accordantly. (Starred environment however, are defined independently from the normal version.) They can behave almost the same or completely different depending how they are coded. ...


13

\section is not defined via \secdef. So there is no \@ssection. This may work: \makeatletter \let\latex@section\section \def\section{\secdef\my@section{\latex@section*}} \def\my@section[#1]#2{...} \makeatother So \section* will call \latex@section*, while \section{title} will call \my@section[title]{title} while \section[x]{title} will call ...


13

Package hyperref needs the counter values to generate unique anchor names. But there are counter values that are not unique. For example, you have several sections with number 1. Because of this, hyperref has introduced \theH<counter> and prefers it over \the<counter> for use in anchor names. \the<counter> might contain weird or duplicate ...


13

There are basically two ways of defining commands with a *-variant. Traditional way \newcommand{\foo}{\@ifstar\@sfoo\@foo} \newcommand{\@sfoo}{something for the *-version} \newcommand{\@foo}{something for the plain version} where \@sfoo and \@foo may have arguments; the names are arbitrary, of course: they are two other commands. Many variations are ...



Only top voted, non community-wiki answers of a minimum length are eligible