Text Formatting ⇒ Automatically format keywords (bold, italicize, etc)
Automatically format keywords (bold, italicize, etc)
Is there a command or package that will allow me to automatically format keywords (bold, italicize, etc)? How do I do this?
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
Latex editor of choice: TexWorks (for dual view feature)
NEW: TikZ book now 40% off at Amazon.com for a short time.

Automatically format keywords (bold, italicize, etc)
What do you mean with keywords?
I'm guessing you want certain words in your document having a specific format:
With the first command, LaTeX prints the word 'keyword' in italic when you insert the command \keyword (so with the slash). The latter one does the same, but then in boldface.
I'm guessing you want certain words in your document having a specific format:
Code: Select all
\newcommand{\keyword}{\textit{keyword}}
\newcommand{\keyword}{\textbf{keyword}}
howtoTeX.com - Your LaTeX resource site (Tips, Tricks, Templates and more!)
Follow howtoTeX on twitter
Follow howtoTeX on twitter
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Automatically format keywords (bold, italicize, etc)
Are we talking about a code listing or just about emphasis of words?ptrcao wrote:Is there a command or package that will allow me to automatically format keywords (bold, italicize, etc)? How do I do this?
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Automatically format keywords (bold, italicize, etc)
By keyword, I just mean words of my choice which I'd like to format, such as book titles, etc. which need to be italicised.
Isn't there a function that will search for all instances of the keyword and format it according to my desire?
This approach
works too, but LaTeX then ignores whitespaces after it for some reason. I'm not sure why. I can include a whitespace after the keyword such as:
But I'm still curious to know if there is a search and format function in LaTeX.
Isn't there a function that will search for all instances of the keyword and format it according to my desire?
This approach
Code: Select all
\newcommand{\keyword}{\textit{keyword}}
\newcommand{\keyword}{\textbf{keyword}}
Code: Select all
\newcommand{\keyword}{\textit{keyword }}
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
Latex editor of choice: TexWorks (for dual view feature)
Automatically format keywords (bold, italicize, etc)
Yep, the whitespace can be quite annoying. A possible fix would be:
Code: Select all
usepackage{xspace}
\newcommand{\keyword}{\textit{keyword\xspace}}
Last edited by Frits on Sun Feb 20, 2011 2:03 pm, edited 1 time in total.
howtoTeX.com - Your LaTeX resource site (Tips, Tricks, Templates and more!)
Follow howtoTeX on twitter
Follow howtoTeX on twitter
Automatically format keywords (bold, italicize, etc)
What about titles of books like "The Lord of The Rings", which have multiple words interrupted by spaces? You can't have
because only the "The" in this instance would be included in the command.
Code: Select all
\newcommand{\The Lord of The Rings}{\textit{The Lord of The Rings}}
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
Latex editor of choice: TexWorks (for dual view feature)
Automatically format keywords (bold, italicize, etc)
I edited my post above for a fix on that whitespace at the end.
For your Lord of Rings question: That's a nasty one. Isn't it possible (and easier) to define:
For your Lord of Rings question: That's a nasty one. Isn't it possible (and easier) to define:
Code: Select all
\newcommand{\lotr}{\textit{The Lord of The Rings}}
howtoTeX.com - Your LaTeX resource site (Tips, Tricks, Templates and more!)
Follow howtoTeX on twitter
Follow howtoTeX on twitter
Automatically format keywords (bold, italicize, etc)
Ah yes, how convenient, I see somebody came up with a function just for this very situation; it appears \xspace takes care of it all so you don't have to think about it.Frits wrote:I edited my post above for a fix on that whitespace at the end.
For your Lord of Rings question: That's a nasty one. Isn't it possible (and easier) to define:Code: Select all
\newcommand{\lotr}{\textit{The Lord of The Rings}}
I originally thought you could do
Code: Select all
\newcommand{\The-Lord-of-The-Rings}{\textit{The Lord of The Rings}}
Code: Select all
\newcommand{\The_Lord_of_The_Rings}{\textit{The Lord of The Rings}}
And right, your suggestion
Code: Select all
\newcommand{\lotr}{\textit{The Lord of The Rings}}
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
Latex editor of choice: TexWorks (for dual view feature)