[Tex/LaTex] How print error or warning messages in the main document with LaTeX without using TeX code

errorswarnings

I simply want to print out some warning and error messages in some cases. I only find solutions using TeX-code (makeatletter…) or inside package code (\PackageError). For the latter one I wasn't able to find a documentation.

Is there another solution?

\documentclass{article}
\usepackage{xltxtra}
\usepackage{polyglossia}
\setdefaultlanguage[spelling=new]{german}
\usepackage{ifthen}

\newcommand{\mymacro}[1]{%
    \ifthenelse{ \equal{#1}{A} }
    {A case}
    {%
        \ifthenelse{ \equal{#1}{B} }
        {B case}
        {%
            \ifthenelse{ \equal{#1}{C} }
            {C case}
            {%
                % print out error message that
                % only A, B or C are allowed
                % values
            }
        }

    }
}

\begin{document}
\mymacro{X} % error
\end{document}

Best Answer

\documentclass{article}
\usepackage{xltxtra}
\usepackage{polyglossia}
\setdefaultlanguage[spelling=new]{german}
\usepackage{ifthen}

\newcommand{\mymacro}[1]{%
    \ifthenelse{ \equal{#1}{A} }%
    {A case}%
    {%
        \ifthenelse{ \equal{#1}{B} }%%%
        {B case}%%%
        {%
            \ifthenelse{ \equal{#1}{C} }%%%
            {C case}%%%
            {%
               \GenericError{[mycode] }{Bad input}%
                            {[mycode] Only A B or C\MessageBreak allowed}%
                            {read the doc}%%%
            }%%
        }%%
%%
    }%%
}

\begin{document}
\mymacro{X} % error
\end{document}

produces

! Bad input.

[mycode] Only A B or C
[mycode] allowed
Type  H <return>  for immediate help.
 ...                                              

l.27 \mymacro{X}
                 % error
? h
read the doc
? 
Related Question