I want to declare a variable in class that takes in the font name from the preamble of the TeX
file.
Something like \docFont{<Variable>}
. Is there a command that could nullify the space key in latex? For example \docFont{ Arial }
would return the same result as \docFont{Arial}
.
My myclass.cls
File is something like this:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myclass}[2019/04/09 Standard HomeWork Template]
\LoadClass[a4paper,12pt,onecolumn,final]{article}
\RequirePackge{etoolbox}
\def\hFont#1{\gdef\@hFont{#1}}
\def\@hFont{\@latex@warning@no@line{No \noexpand\hFont given}}
\BeforeBeginEnvironment{document}{
\RequirePackage{xepersian}
\settextfont{\@hFont}
}
And my *.Tex
file is something like this:
\documentclass{myclass}
\hFont{Arial} %Document Persian Font
\begin{document}
something
\end{document}
Best Answer
You can use the trimspaces package for this purpose.
Simple examples
Here is another way that first stores the result of the trimming operation in a macro (
\my@tmp@trimmed
), then expands this macro:Overview of the possibilities
The trimspaces package offers several variants depending on what you want:
\trim@pre@space
and\trim@pre@space@noexp
; right:\trim@post@space
,\trim@post@space@noexp
; both:\trim@spaces
,\trim@spaces@noexp
);@noexp
variant in the examples, that just trims without expanding; otherwise, see\trim@spaces
in the package documentation and below).It also allows one to trim the contents of an already-existing macro. Here is the example from the documentation concerning this point:
is equivalent to
\trim@pre@space@in
and\trim@post@space@in
offer analoguous functionality for left-only, resp. right-only trimming.Difference between
\trim@spaces
and\trim@spaces@noexp
The following example illustrates the functional difference between
\trim@spaces
and\trim@spaces@noexp
1: the former expands tokens from its argument whereas the latter doesn't (they can then be expanded “at the last moment”, which is often desirable).Corner cases
This last example explores a few corner cases with various kinds of spaces:
Footnote
\trim@spaces@noexp
requires an eTeX engine, while\trim@spaces
doesn't.