Fonts & Character SetsMacro for Worked Example Font

Information and discussion about fonts and character sets (e.g. how to use language specific characters)
LaTexLearner
Posts: 139
Joined: Tue Mar 10, 2015 11:06 am

Macro for Worked Example Font

Post by LaTexLearner »

Is there an easy to way to make a global macro that can make my worked examples:
(1) Look at least somewhat handwritten,
(2) Obviously distinguishable from my normal text and the questions, and
(3) Work for math mode as well.

E.G. I made this in Microsoft Word. My students need worked examples and instructions to be UBER clear, which is why the worked example font MUST be separate from the normal font. What is the easiest way to make this happen?

Image

I also need to figure out how to load a new font package... I wasn't able to make sense of the threads and websites I read about that. I'm actually a little surprised at how complex it is to change fonts in LaTeX... or am I missing something?

Thanks!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Macro for Worked Example Font

Post by Johannes_B »

Fonts are ... well ... special.

Deciding what font to choose is something that should be done by experts, but it is not.

Installing fonts can be a pain. Often.

Below an example, that uses the font called JD from the emerald package. Due to its license it is not included in TeX Live and needs to be installed first (I followed Silkes advice).

Code: Select all

\documentclass{article}
\usepackage{emerald}
\usepackage[T1]{fontenc}
\newcommand{\studentfillin}[1]{\begingroup\ECFJD#1\endgroup}
\begin{document}
Fill in the blanks! \studentfillin{Johnathan Mueller} Normal text
again
\end{document}
latexlearnerStudentFillin.png
latexlearnerStudentFillin.png (21.32 KiB) Viewed 8841 times
You can find other examples in the LaTex font catalogue.

If you have a handwritten font as otf, you are lucky. Modern engines like XeTeX and LuaTeX can handle them easily, making working with different fonts a pleasure.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
LaTexLearner
Posts: 139
Joined: Tue Mar 10, 2015 11:06 am

Macro for Worked Example Font

Post by LaTexLearner »

That looks really complicated, especially all those instructions for installation in the link which I basically didn't understand at all! lol

Perhaps I should settle for another font that is easier to install?

All I really want is to be able to do something like this:

Code: Select all


\usepackage{HANDWRITTEN-FONT}

\newenvironment{ex}
  {\begin{itshape}\begin{large}\begin{HANDWRITTEN-FONT}}
  {\end{HANDWRITTEN-FONT}\end{large}\end{itshape}}

...

\begin{ex}
This will be the worked example text.
\end{ex}

User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Macro for Worked Example Font

Post by Johannes_B »

Choosing and installing a font is one thing, defining a command or environment for LaTeX is another.

Please note, that \itshape and \large are commands, not environments.

Code: Select all

\newenvironment{example}{\begingroup\<fontswitch>\itshape\large}{\endgroup}
* Please note, that my example aboce does not use \itshape or \textit, as the JD font is only available in normal (ie. not italic or slanted or bold).

There are more fonts to discover in the cataloge (cf. link above) and many many more fonts in the wide open of the world wide web in otf-format easily usable with XeTeX and LuaTeX.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Macro for Worked Example Font

Post by Johannes_B »

An example using XeLaTeX. The font can be found at 1001 fonts and is free (also for commercial use).

Code: Select all

% arara: xelatex
\documentclass{article}
\usepackage{fontspec}
\newfontface\studentwrite{James Almacen}
\newcommand{\studentfillin}[1]{\begingroup\ECFJD#1\endgroup}
\newenvironment{example}{\begingroup\studentwrite\large}{\endgroup}
\begin{document}
Fill in the blanks! \begin{example}Johnathan Mueller\end{example} Normal text
again
\end{document}
latexlearnerXelatex.png
latexlearnerXelatex.png (11.37 KiB) Viewed 8827 times
Of course, a free font has clear short comings, as only very basic charackters are supported. Try the german umlauts, they will fail.
If you are trying some time to typeset handwritten math (ie. an integral sign or something) be warned: Nothing out there. Before starting too look, get a tablet PC and a pen and trace your own handwriting. A bit of fontforge magic and you have your very own set of a font.



Maybe a simple calligraphic font is enough for you?

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}
\newcommand{\studentfillin}[1]{\begingroup\usefont{T1}{qzc}{m}{it}\large#1\endgroup}
\begin{document}
Fill in the blanks! \studentfillin{Johnathan Mueller} Normal text
again
\end{document}
This time, you can click on Open in writelatex and see the output ;-)

by the way, this is the perfect timing to mention italic correction.

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}
\newcommand{\studentfillin}[1]{\begingroup\usefont{T1}{qzc}{m}{it}\large#1\endgroup}
\begin{document}
Fill in the blanks! \studentfillin{Johnathan Mueller}Normal text again\par
\renewcommand{\studentfillin}[1]{\begingroup\usefont{T1}{qzc}{m}{it}\large#1\/\endgroup}
Fill in the blanks! \studentfillin{Johnathan Mueller}Normal text again\par
\end{document}
Please compare the different output. Be sure not to be sleepy, you need to take a close look ;-)
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
LaTexLearner
Posts: 139
Joined: Tue Mar 10, 2015 11:06 am

Macro for Worked Example Font

Post by LaTexLearner »

Johannes_B wrote: ... Of course, a free font has clear short comings, as only very basic charackters are supported. Try the german umlauts, they will fail.
If you are trying some time to typeset handwritten math (ie. an integral sign or something) be warned: Nothing out there. Before starting too look, get a tablet PC and a pen and trace your own handwriting. A bit of fontforge magic and you have your very own set of a font.
Yes... although I won't be doing any high-level math, as this is mostly for struggling students 16 and under.

I just need the font to be able to do basic text and fairly simple LaTeX math such as numerals, fractions, decimals, percents, etc...
Johannes_B wrote: Maybe a simple calligraphic font is enough for you?

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}
\newcommand{\studentfillin}[1]{\begingroup\usefont{T1}{qzc}{m}{it}\large#1\endgroup}
\begin{document}
Fill in the blanks! \studentfillin{Johnathan Mueller} Normal text
again
\end{document}
I think I would be satisfied with something like this font, except it does not appear to include math, i.e. the fraction here looks like it came from a normal LaTeX document.

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}
\newcommand{\studentfillin}[1]{\begingroup\usefont{T1}{qzc}{m}{it}\large#1\endgroup}

\begin{document}

Fill in the blanks!

\studentfillin{Johnathan Mueller} 

\studentfillin{\(\frac{2}{3}\)} % This comes out looking just like normal LaTeX math

Normal text
again
\end{document}
Johannes_B wrote: by the way, this is the perfect timing to mention italic correction.

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}
\newcommand{\studentfillin}[1]{\begingroup\usefont{T1}{qzc}{m}{it}\large#1\endgroup}
\begin{document}
Fill in the blanks! \studentfillin{Johnathan Mueller}Normal text again\par
\renewcommand{\studentfillin}[1]{\begingroup\usefont{T1}{qzc}{m}{it}\large#1\/\endgroup}
Fill in the blanks! \studentfillin{Johnathan Mueller}Normal text again\par
\end{document}
Please compare the different output. Be sure not to be sleepy, you need to take a close look ;-)
Did not get this... lol. Will look at in more detail tonight. I'm not even sure what italic correction is...
LaTexLearner
Posts: 139
Joined: Tue Mar 10, 2015 11:06 am

Macro for Worked Example Font

Post by LaTexLearner »

Johannes_B wrote: Choosing and installing a font is one thing, defining a command or environment for LaTeX is another.

Please note, that \itshape and \large are commands, not environments.

Code: Select all

\newenvironment{example}{\begingroup\<fontswitch>\itshape\large}{\endgroup}
* Please note, that my example aboce does not use \itshape or \textit, as the JD font is only available in normal (ie. not italic or slanted or bold).
I understand that \itshape and \large are commands, but what is the advantage of doing things like you did in the above quote vs what I did here which worked?

Code: Select all

\documentclass{article}

\usepackage[utf8]{inputenc}

\newenvironment{ex}
{\begin{itshape}\begin{Large}}
{\end{Large}\end{itshape}}

\begin{document}

Normal text before.

\begin{ex}
I hope this worked example text progresses towards something more handwritten-looking.
\end{ex}

Normal text after.

\end{document}

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Macro for Worked Example Font

Post by cgnieder »

Johannes_B wrote:

Code: Select all

\newenvironment{example}{\begingroup\<fontswitch>\itshape\large}{\endgroup}
Just a small comment: since environments already form groups (opened in \begin and closed in \end) the \begingroup/\endgroup is not strictly necessary here.

Regards
site moderator & package author
LaTexLearner
Posts: 139
Joined: Tue Mar 10, 2015 11:06 am

Macro for Worked Example Font

Post by LaTexLearner »

cgnieder wrote:
Johannes_B wrote:

Code: Select all

\newenvironment{example}{\begingroup\<fontswitch>\itshape\large}{\endgroup}
Just a small comment: since environments already form groups (opened in \begin and closed in \end) the \begingroup/\endgroup is not strictly necessary here.

Regards
Then what would you put in the final braces of custom environment if it contains something like:

Code: Select all

\newenvironment{\name}{\itshape}{?}
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Macro for Worked Example Font

Post by cgnieder »

LaTexLearner wrote:Then what would you put in the final braces of custom environment if it contains something like:

Code: Select all

\newenvironment{\name}{\itshape}{?}
Leave it empty:

Code: Select all

\newenvironment{name}{\itshape}{}
or maybe

Code: Select all

\newenvironment{name}{\itshape}{\ignorespacesafterend}
or in this case even

Code: Select all

\newenvironment{name}{\unskip\itshape}{\ignorespacesafterend}

Code: Select all

\documentclass{article}

\newenvironment{name}{\itshape}{}
\newenvironment{name2}{\itshape}{\ignorespacesafterend}
\newenvironment{name3}{\unskip\itshape}{\ignorespacesafterend}

\begin{document}

Text
\begin{name}
  name
\end{name}
Text

Text
\begin{name2}
  name
\end{name2}
Text

Text
\begin{name3}
name
\end{name3}
Text

\end{document}
BTW: the name of an environment in the first argument of \newenvironment should not be a command!

Regards
site moderator & package author
Post Reply