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)


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.}

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


\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} }?


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.



      \try@load@fontshape % try always
       \csname\curr@fontshape\endcsname \relax
       \expandafter\gdef\csname \curr@fontshape/sub\endcsname{}% new      

 { \fontfamily{ninja}\selectfont #1
 \ifcsname \f@encoding/\f@family/\f@series/n/sub\endcsname
  \PackageError{NinjaSetup}{Not installed}{Do this}

\ninjaFont{It works?}
  • 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. Jan 30, 2015 at 12:04
  • You are correct. I messed up! Jan 30, 2015 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. Jan 30, 2015 at 12:47
  • Added minimum example Jan 30, 2015 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. Jan 30, 2015 at 13:37


You must log in to answer this question.

Browse other questions tagged .