Changing \thesection (latex) locally - latex

How may I locally change \thesection command?
For example, in all chapters I'd like to have the usual \thesection, like
\arabic{chapter}.\arabic{section}, but in a single chapter I'd prefer to have just \arabic{section}.

Just set
{
\chapter{Here happen strange things}
\renewcommand{\thesection}{\arabic{section}}
\section{Without chapter-number}
}
By wrapping your modified chapter into braces, the renewcommand will only work in this single chapter, not outside of the block.
If needed don't forget to also change the numbering for subsection and subsubsection.

Related

How to prevent LaTeX from hyphenating words containing a dash?

I would like to globally prevent LaTeX from hyphenating 'Objective-C'. I am aware of the \hyphenation command, but I don't see how I can make use of it. If I pass 'Objective-C' to this command, the dash will be treated as a hint to hyphenate the word there.
One solution I found is wrapping Objective-C into an mbox each time I use it. However, the document I am writing contains this name a lot, and wrapping it into an mbox each time is ugly (as is defining a command and using this over and over again in the source code).
Why is defining a new command ugly? It's how \LaTeX\ defines itself.
\def\ObjectiveC{\mbox{Objective-C}}
Use \nobreakdash. That's what LyX produces when I insert a nonbreakingdash and convert it to tex.
As suggested here, you could define a command like this:
\newcommand\dash{\nobreakdash-\hspace{0pt}}
and use it like this
Consider the $n$\dash dimensional manifold ...
Also, you could use the babel package and use "~ as a protected hyphen. I'm not sure if using babel is advisable when writing in english, though.

Latex Beamer: How is it possible to make piece of text in a frame in italics?

I am using Beamer in order to make a presentation. In one of the frames I want to write something like this:
"Italics is like that"
I used a command \it of Beamer for doing this:
\it{Italics} is like that
But as a result I get:
"Italics is like that"
Is it possible to make italics only a piece of text?
I believe you're looking for \textit{}.
Also, in the future, consider asking LaTeX questions on the TeX - LaTeX Stack Exchange site.
\it is a switch, it changes the font series starting from the point it was issued till the end of the current block. Therefore you have to enclose the block of text it should affect:
{\it Italics} is like that
Alternatively you can use \textit as suggested by gotgenes which only affects the text passed to the command within braces:
\textit{Italics} is like that.
What about \emph{text} ?

Trouble wrapping scalebox in an environment with fixed scale factor

The graphicx package provides a scalebox command. I'd like to encapsulate it in an environment like that:
\newenvironment{scaleb}{ \scalebox{0.7}{ } {}}
However, the second example below works, but the first one outputs the text without scaling and destroys all my layout.
\begin{scaleb}test\end{scaleb}
\scalebox{0.7}{test}
What am I doing wrong ?
You are trying to have unmatched { and } and the begin and end part of the environment, which TeX won't let you do. Your \newenvironment is read as follows by LaTeX:
\newenvironment{scaleb}{ \scalebox{0.7}{} {} }
so you have an empty \scalebox and no endscaleb-part. Accessing the content of an environment is slightly tricky and depends on your circumstances (can your scaleb environments be nested, do you want to be able to build new environments on top of scaleb so that you don't have a literal "\end{scaleb}" in your document, etc.)
Maybe the environ package can help you: http://www.ctan.org/tex-archive/macros/latex/contrib/environ/.

wrap LaTeX command in environment

How can I wrap a LaTeX command in an environment? In essence, how can I turn \somecommand{contents} into \begin{somecommand} contents \end{somecommand}? I have tried the obvious in creating a new environment as such:
\newenvironment{somecommand}[0]{
\somecommand{
}
{
}
}
but this causes problems with the curly brackets. Let me give a more concrete example. Say that you want to create the environment very-important and you want to use the command emph to accomplish this. An straightforward (but incorrect) solution would be to write something as
\newenvironment{very-important}[0]{
\emph{
}
{
}
}
The problem here is that the command works with the information that is found inside the environment, so it is not one of the opening commands of the environment, nor is it a closing command of the environment. The question is then: how can you do this?
This can be done with the environ package as follows:
\usepackage{environ}
...
\NewEnviron{very-important}{\emph{\BODY}}
\BODY contains the body of the environment, and environments may be nested. See the documentation for more details.
It seems that now I can guess what is the question.
\newenvironment{very-important}{\startimportant}{}
\def\startimportant#1\end{\emph{#1}\end}
\begin{very-important}
Something
\end{very-important}
This solution works well.
But IMHO it is bad idea to wrap all text in the environment. Why?
There are two ways to do something with the text.
For example, you want to change the font and use italic.
The first method. \textit{sentence written in italics}
The second method. {\it sentence written in italics\/}
What is the difference? The thing is that first method use the second one.
\it macro changes the font and the brace } changes it back.
\textit macro reads the full argument, changes the font and inserts the argument again:
\textit is defined roughly as follows (not exactly).
\def\texit#1{{\it#1\/}}
The first method is always doing extra work. It reads the argument twice.
Almost always, you can make changes and then you can everything back.
Eventually why do you use the environment? Use macros.
\veryimportant{
Any thought
}
A Simpler way could be:
\newenvironment{somecommand}[0]{
\somecommand\bgroup
}
{
\egroup
}
Explanation: \bgroup works like { and \egroup works like }.
New environment somecommand defines the macro \somecommand.
You can not use macro with the same name \somecommand inside.
Moreover you should write
\newenvironment{name}{openning command}{closing commands}
rather than
\newenvironment{somecommand}[0]{ \somecommand{ } { } }
You obviously have a problem with closing commands.
define command
\newcommnad{eqn}{1}{\begin{equation}#1\end{equation}}
will change
\eqn{x^2=y}
to
\begin{equation}
x^2=y
\end{equation}
I think

Turning off marginpar (marginparwidth) while in multicols environment

I'm trying to turn off marginpar when starting a new multicols environment with this:
\renewenvironment{multicols}[1]{%
\let\oldmarginparwidth\marginparwidth
\setlength{\marginparwidth}{0}%
\begin{multicols}{#1}
}{%
\end{multicols}%
\setlength{\marginparwidth}{\oldmarginparwidth}%
}
However, it doesn't work. What am I missing?
The command you've got there won't work mid-page, you need to use the changepage package to do that.
\usepackage{changepage}
I take it you're trying to take up the full width of the page. I nicked this from the tufte-latex class:
First, define an 'overhang' amount that'll be added to the textwidth at the beginning and subtracted at the end:
\newlength{\overhang}
\setlength{\overhang}{\marginparwidth}
\addtolength{\overhang}{\marginparsep}
Then use \adjustwidth with the overhang amount when you want to remove marginpar space:
\begin{adjustwidth}{}{-\overhang}
% This will be displayed full-width
\end{adjustwidth}{}{-\overhang}
As Damien pointed out, you can still use marginpars like this, they'll just exceed the pagewidth. \multicols will prevent you from using floats, however.
Hope that's what you need!
I'm not sure exactly what you're looking for here, but generally marginpars aren't allowed in multicols already. From the multicol documentation:
...floats and marginpars are not allowed in the current implementation [This is dictated by lack of time. To implement floats one has to reimplement the whole LATEX output routine.].
I have managed to get it working by using the chngpage package and defining a new environment which sets/resets different values before/after that environment.
However, I still have a problem on the last page of each \chapter: header width on the last page of the chapter

Resources