For the underscore, the following works:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[ngerman]{babel}
\catcode`\_=\active
\protected\def_{\begingroup\itshape\aftergroup\/\let_\endgroup}
\begin{document}
Hello \textit{World!} How are you?
Hello _World!_ How are _you?
I'm fine._ And you?
_I'm fine, too.
Glad to hear that._
\end{document}
However, it is a bit crazy and unstable. If you want to use it only for short texts (not spanning multiple paragraphs), the following would be better. (It doesn't work in the above example, since there we span multiple pagraphs. In real, it will throw an error if you put odd number of _
in one paragraph.)
\catcode`\_=\active
\protected\def_#1_{\textit{#1}}
You can use the same ideas for the star. The problem is, that \section*{Text}
will suddenly stop working. Variant 1:
\catcode`\*=\active
\protected\def*{\begingroup\bfseries\let*\endgroup}
Variant 2:
\catcode`\*=\active
\protected\def*#1*{\textbf{#1}}
If you don't use math at all, just use ^
instead of *
and it should be ok.
How does it work: The primitive macro \catcode
makes _
\active
so that we can define it as any other command.
In Variant 1, we define it to (1) start a group (2) start italic text (3) add italic correction to the end of the italic text (4) make the one next _
end the group we started. By the end of the group, the re-definition of _
is forgotten so another _
will again start an italic text.
The Variant 2 is even simpler: When _
is found, a second _
is looked for, end everything inbetween is put into \textit
.
The \protected
directive makes sure that _
is written as _
in the auxiliary files, which is necessary for it to behave correctly.
Load a font that has the combination bf+it
, e.g.
\usepackage{lmodern}
MWE
\documentclass{beamer}
\usetheme{Copenhagen}
\usepackage{lmodern}
\begin{document}
\frame{
A number is \textbf{\textit{x}-smooth} if ...\\
A number is \textbf{\emph{x}-smooth} if ...
}
\end{document}
Best Answer
No
Really, no!
$ ... $
is the TeX way of entering math mode - specifically, inline math mode. What this means is that it puts you in a mode configured perfectly for mathematics - not italic text.Using
$ ... $
to italicise text will produce some very bad results.Unless you've got some strange set up, spaces will be ignored, so
Produces
The spacing between letters in a word will also be awful, because it's designed for the spacing between strings of mathematical variables, like ab + cd = efg or whatever, not for words. As a result, you'll get irregular gaps between letters:
Look at the spacing between the r and the e.
Because you're in math mode, text mode commands will not work.
Produces the error
Also, if you're using different fonts to the default, your italic font may be different to your maths font.
But leaving all this aside, it violates one of the principles of LaTeX, which is logical structure. One of the key ideas is that I have meaningful commands and environments for producing a given structure. So, instead of hand typing out an enumerated list, putting in all the indents and stuff manually each time, I use an
enumerate
environment. If I want some mathematics, I enter into math mode. I shouldn't really be using math mode as a hack for something which is not maths, because it messes up the structure of my.tex
file.On that theme, you might like consider using
\emph{foo}
. Now\emph{}
is for emphasising things and by default its behaviour is to make things italic. It also handles nested emphasis, so thatProduces
Note how the ever is upright.
Here, I am not using a low-level font change command, I've got a structure - emphasis. And when I want to emphasise something I use that. This means that, if I want to change how things are emphasised in my document without going through and changing all the
\textit
s, I can do it by simply redefining\emph
. I myself almost never use\textit
in a document, but I do usually define a number of commands, such as\work
for works (books, plays, movies and so on). Usually such titles are set in italic.But I can effortlessly change this so that all of my titles are put in quotation marks instead.
Another thing you might want to look into is using an editor that can speed up the process of inputting commands by defining keyboard shortcuts. Have a look here and see if any take your fancy.