0

I googled about this problem with no result yet. You might discourage this, but is there a way to suppress errors?

This is an example how it should work.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}

\begin{document}

\ifx\foo\undefined
\else
\foo
\fi

\def\foo{anything}

\ifx\foo\undefined
\else
\foo
\fi

should equal

%\suppressUndefError

\foo

\def\foo{anything}

\foo

%\Unsuppress

\end{document}

The purpose of this is, to ease the work for layout developers for my package. If this isn't possible or a very bad idea for some reasons, the solution would be to

A) tell them to insert this by themselves

B) define a macro \def\secure@Maestro#1{\ifx#1\undefined\else #1\fi}

B doesnt work since I can't pass macros to it, which are undefined.


Edit:

For anyone who encounters the same problem, this [Trapping LaTeX error/warning] might help.

MaestroGlanz
  • 2,348
  • What do you mean by suppress errors? That (La)TeX ignores them and goes to next content? What is wrong with \@ifundefined{foo}{}{} ?? –  May 27 '16 at 18:29
  • @ChristianHupfer Either that or replaces them by \relax. They should behave like \relax. – MaestroGlanz May 27 '16 at 18:30
  • why not just pre-define \foo to \relax or \empty so it isn't undefined, – David Carlisle May 27 '16 at 18:32
  • for B didn't you mean \def\secure@Maestro#1{\ifx#1\undefined\else #1\fi} so that it's testing the macro that's about to be used? – David Carlisle May 27 '16 at 18:33
  • @ChristianHupfer Simple, the layouters should be able to make a layout like \huge{\title}\par\author\\ \webadress without worrying if one of them really exists. – MaestroGlanz May 27 '16 at 18:35
  • \providecommand{\foo} ;-) –  May 27 '16 at 18:36
  • @ChristianHupfer How could I forget about this. But I would prefer the option with error suppression, since this would be more convenient for the users. – MaestroGlanz May 27 '16 at 18:39
  • it is far more normal for the usage explained in the comment for the class to use \def\author{} or \def\author{\ClassError{MG}{author not set}{} to silently ignore or make a specific error rather than an undefined command error. if for example you just ignore \author you would get an error from \\ about no line to end. – David Carlisle May 27 '16 at 19:19
  • you have fixed B to test \ifx# but now the following sentence is false, b does work as you can pass it undefined macros – David Carlisle May 27 '16 at 19:21
  • 1
    I'm not sure if I should wish you users. Do you really think they would like to get no errors if they make a typo like \webaddress and get no output? Btw: do you really want to type the author in \huge? – Ulrike Fischer May 27 '16 at 19:22
  • 1
    @UlrikeFischer since the whole document would be in huge having the author at that size wouldn't be so bad:-) – David Carlisle May 27 '16 at 19:27
  • @MaestroGlanz: By the way: You're not doing the layout yourself? –  May 27 '16 at 20:13
  • A well designed package must be extendable. It will be similar to the concept of moderncv. So I do only a base layout, which can easily be replaced by custom ones. The point Ulrike mentioned is correct, but this is - as I think - more acceptable than putting a ifundefined around every item. If I can do it, the way I intend this, every school boy can design his own layout. – MaestroGlanz May 27 '16 at 21:52
  • 2
    @MaestroGlanz Excuse me, how is "extendable" incompatible with "not generating errors", and how is "generating errors" considered "well designed"? – yo' May 27 '16 at 22:16
  • @yo' It would be a dirty trade. I would trade ignoring some possible (unimportant) errors for more user-friendly usage. The user-friendly usage is my number one priority after working properly. – MaestroGlanz May 27 '16 at 22:24
  • 1
    And "dirty trade" is more compatible with "well designed", especially in a place where it is completely avoidable? – yo' May 27 '16 at 22:25
  • 3
    avoiding errors should be the number one priority if the class is to be usable, so there isn't really such a trade that can be made. – David Carlisle May 27 '16 at 22:28
  • 2
    biblatex is a very extendable package, you can new fields, categories, cite commands, format instructions -- without any need to ignore errors. Beside: even if you get latex to ignore the errors, you won't be able to fool the editors. No user will like if texstudio and the other editors shows a lot of red lines. And every expert in every forum will recommend not to use such a package. – Ulrike Fischer May 27 '16 at 22:29
  • Creating a titlepage ( i gues this is what you are talking about) is very simple, without any macros – Johannes_B May 29 '16 at 06:22
  • @Johannes_B No, this is not what I'm talking about. It is about songs, which have title, author, etc. and will be included via command from a predefined songbook. The meta data stored in the songbook will be put around the included song depending on a predefined design. This design can be changed and individually chosen. I am not talking about \maketitlepage here. – MaestroGlanz May 29 '16 at 08:04

1 Answers1

3

you can use \scrollmode or \batchmode so that TeX does not stop on errors but it would be a really bad idea to do so.

The class should simply predefine constructs like \author if you have

\def\author{your name goes here}

in the class then you get that text unless the user sets author, or you could instead have

\def\author{\ClassWarning{MG}{author name not set}}

or anything else that you need.

David Carlisle
  • 757,742
  • The problem is, that all the commands like \author are automatically generated from meta data. This is flexibility at its maximum, but therefore also mostly unpredictable. But this here seems to be pretty useful. – MaestroGlanz May 27 '16 at 21:52
  • 1
    @MaestroGlanz telling people to use commands like \author that may or may not be defined and then masking tex's error reporting would be a usability disaster, I wouldn't even half-consider it for a public class. provide an interface like \MGuse{author} which can simply be \def\MGuse#1{\csname#1\endcsname} then it will run \author if it is defined and do nothing otherwise. – David Carlisle May 27 '16 at 22:10
  • I will try this, since the mode thing did not lead where I wanted to. The problem (or the feature) is, that any person can define own meta data and use it without me knowing about it. That means, that other authors dont need to rely on me regarding their needs. It is a basic concept, that I do not limit the number of attributes like \author or \ISBNnummer. The user can create a database with i.e. 500 songs, poems, prayers, whatever and create custom meta data for any of it. After that he or she can create a layout which uses this meta data. – MaestroGlanz May 27 '16 at 22:18