1

I need to throw an error, should a certain font not be installed.

I have a font in a subfolder: /font/NinjaFont.ttf. This must be installed via certain commands (not important for this - but here: http://math.stanford.edu/~jyzhao/latexfonts.php)

EDIT:

If it's not installed I get about 200 error messages and 2 warnings: ...MiKTeX\2.9\tex\latex\pst-text\pst-text.sty:31: LaTeX Font Warning: Font shape 'T1/Fonts/NinjaFont/m' undefined(Font) using 'T1/cmr/m/n' instead on input line 31. ...pst-text.sty:31: LaTeX Font Warning: Some font shapes were not available, defaults substituted.

I need to detect, whether T1/Fonts/NinjaFont/m is defined.

The following code can help me some of the way:

\PackageError{NinjaPackage}{The ninja font is not defined}{See ninja instructions.}
\stop

Not I just need to detect the font, so I can throw the error. Anyone have a solution or pointers to where I can find the answer?

More EDIT:

Example files:

T1-WGL4.enc: http://math.stanford.edu/~jyzhao/T1-WGL4.enc

t1ninja.df:

\ProvidesFile{t1ninja.fd}
\DeclareFontFamily{T1}{ninja}{}
\DeclareFontShape{T1}{ninja}{m}{n}{ <-> ninja}{}
\pdfmapline{+ninja\space <ninja.ttf\space <T1-WGL4.enc}

I think it would be around here, that the compiler realizes, that the font does not exist in the folder with other fonts.

Can I do a \xifelsethen{ {warningThrown} {Error} {noError} }?

EDIT 4:

Based on previous answers this seems to work out nice. I have to install the package globally, then I'm for sure it will work.

\documentclass{article}

\usepackage{etoolbox}

\makeatletter
\def\define@newfont{%
  \begingroup
    \let\typeout\@font@info
    \escapechar\m@ne
    \expandafter\expandafter\expandafter
       \split@name\expandafter\string\font@name\@nil
      \try@load@fontshape % try always
    \expandafter\ifx
       \csname\curr@fontshape\endcsname \relax
       \expandafter\gdef\csname \curr@fontshape/sub\endcsname{}% new      
      \wrong@fontshape\else
      \extract@font\fi
  \endgroup}

\newcommand\ninjaFont[1]{%
 { \fontfamily{ninja}\selectfont #1
 \ifcsname \f@encoding/\f@family/\f@series/n/sub\endcsname
  \PackageError{NinjaSetup}{Not installed}{Do this}
  \stop
 \else 
 \fi
 }}
\makeatother

\begin{document}
\ninjaFont{It works?}
\end{document}
  • 2
    T1/Fonts/NinjaFont/m looks odd, I doubt that you did setup the font commands correctly. Beside this: You get only a warning not an error if this font is undefined. Better make a complete example that demonstrates your problem. – Ulrike Fischer Jan 30 '15 at 12:04
  • You are correct. I messed up! – Rasmus Bækgaard Jan 30 '15 at 12:23
  • Your font setup is wrong, you seem to use a foldername as familyname. You could probably adapt the code here tex.stackexchange.com/questions/218539/… but without an example I won't test. – Ulrike Fischer Jan 30 '15 at 12:47
  • Added minimum example – Rasmus Bækgaard Jan 30 '15 at 13:32
  • If your fd-filed is named t1ninja and font family "ninja" you must call the font as \usefont{T1}{ninja}{m}{n} . And if the ttf-file is named NinjaFont.ttf you must adapt the \pdfmapline command. Beside this it is unclear if you want to check if the fd-file or the ttf-file exists. – Ulrike Fischer Jan 30 '15 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.