Fonts & Character Setsthe courier font

Information and discussion about fonts and character sets (e.g. how to use language specific characters)
allevo
Posts: 49
Joined: Sat Apr 11, 2009 12:09 pm

the courier font

Post by allevo »

excuse me.. i don't explain my thought very well...
i'd like have a command that, passed the name of fonts, set the font of following text.
i'd want use a command like this: \usefont{name of font}
for example:

Code: Select all

\documentclass{book}
\usepackage{fontenc}
\newcommand \usefont[1]{ ?!?!?}
\begin{document}
\usefont{Arial} arial text
\usefont{Charter BT} Charter BT text
\usefont{Humanist} Humanist text
\end{document}
is possible?!?!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

the courier font

Post by frabjous »

Experimenting a little, this sorta does the trick:

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}
\newcommand{\choosefont}[1]{\fontfamily{#1}\selectfont}
\begin{document}

\choosefont{phv} Helvetica text

\choosefont{pcr} Courier text

\choosefont{pzc} Zapf chancery text

\end{document}
I used "choosefont" rather than "usefont" since the latter already seems to have another use.

By default that will let you use the fonts included in the PSNFSS bundle, and you'll have to refer to them by their family names used there. Here's a guide:
http://www.cs.brown.edu/system/software ... nfss2e.pdf

See especially page 9.

If you want more, you'll have to load additional packages. E.g, for the Bera fonts, you might use:

Code: Select all


\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{bera}
\newcommand{\choosefont}[1]{\fontfamily{#1}\selectfont}
\begin{document}

\choosefont{phv} Helvetica text

\choosefont{pcr} Courier text

\choosefont{pzc} Zapf chancery text

\choosefont{fve} Bera Serif text

\choosefont{fvs} Bera Sans text

\end{document}
For the fontfamily names used with the Bera package:
http://ftp.math.purdue.edu/mirrors/ctan ... a/bera.pdf

Someone else might have some better solutions. I'm a newbie myself.

And perhaps it goes without saying, but I hope you have a good reason for wanting this. There's nothing more annoying than reading something that changes fonts often for no good reason. Things tend to look better when one font or font family is used throughout. Just my personal opinion.
allevo
Posts: 49
Joined: Sat Apr 11, 2009 12:09 pm

Re: the courier font

Post by allevo »

thank for all answer!!!!
but what is the parameter that i pass to \fontfamily?!?
where can i find a list containing all parameters?!?!?

EDIT: at pg 9 of the pdf linked there're a list. is it complete?!?!
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

the courier font

Post by localghost »

allevo wrote:[...] but what is the parameter that i pass to \fontfamily?!? [...]
This parameter is an abbreviation which identifies the font definitely.
allevo wrote:[...] where can i find a list containing all parameters?!?!? [...]
I'm not aware of a comprehensive list. But you can take a look at the package files themselves. The packages do in principal nothing else than you can see in my sample code below. They redefine the default settings to make a whole document appear in the chosen font. For more information you can take a look at the PSNFSS or start a search engine and search for the "LaTeX Font Selection Scheme" or "NFSS".
allevo wrote:[...] at pg 9 of the pdf linked there're a list. is it complete?!?!
I only see a single page in this document. But of course the list is complete.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}

\parindent0em

\newcommand*{\berarm}[1]{\usefont{T1}{fve}{m}{n}#1\normalfont}  % Bera Roman
\newcommand*{\berasf}[1]{\usefont{T1}{fvs}{m}{n}#1\normalfont}  % Bera Sans
\newcommand*{\beratt}[1]{\usefont{T1}{fvm}{m}{n}#1\normalfont}  % Bera Mono

\begin{document}
  The quick brown fox jumps over the lazy dog.

  \smallskip
  \berarm{The quick brown fox jumps over the lazy dog.}

  \smallskip
  \berasf{The quick brown fox jumps over the lazy dog.}

  \smallskip
  \beratt{The quick brown fox jumps over the lazy dog.}

  \smallskip
  The quick brown fox jumps over the lazy dog.
\end{document}
Compare the parameters with those you can find in the bera font sample document. Note that bera needs to be installed for this example because the new commands need access to the font definition files. In LaTeX you cannot specify a font like you want to. Perhaps XeTeX is worth a look.
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
allevo
Posts: 49
Joined: Sat Apr 11, 2009 12:09 pm

Re: the courier font

Post by allevo »

thank a million!!!!
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

the courier font

Post by frabjous »

localghost wrote:
allevo wrote:at pg 9 of the pdf linked there're a list. is it complete?!?!
I only see a single page in this document. But of course the list is complete.
I believe he was referring to the first PDF I linked to, the one on PSNFSS, not the second (the one on Bera). The one on Bera has only one page, but the other has more.
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

the courier font

Post by localghost »

frabjous wrote:I believe he was referring to the first PDF I linked to, the one on PSNFSS, not the second (the one on Bera). The one on Bera has only one page, but the other has more.
I see. But for this document it is also true that the data table containing the font shapes is complete.
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Post Reply