LaTeX Tips And Traps

From WeBWorK_wiki
Jump to navigation Jump to search

LaTeX Tips and Traps

Problem authors can type virtually any LaTeX construct in a WeBWorK (PG) problem. There's a few caveats, though.

Remember that the source code of the problem is first interpreted by Perl. The preprocessed, embedded LaTeX code is then passed along to LaTeX for rendering. This means that your code can vary the input that is presented to LaTeX.

Dollar Sign

This procedure requires that the input code be valid Perl code. Since Perl uses the dollar sign '$' to indicate a (scalar) variable name, we cannot use the '$' sign in LaTeX mode. Instead, use \( and \) to begin and end inline LaTeX math mode, and \[ and \] to begin and end LaTeX display mode. To print the dollar sign symbol, use ${DOLLAR} between BEGIN_TEXT and END_TEXT.

Percent Sign

LaTeX interprets a percent sign (%) as starting a comment, which extends to the end of the line. To avoid confusion, wherever you need to have a percent sign appear in a problem, use the $PERCENT display macro.

Right and Left Braces

LaTeX uses \{ to indicate a left brace, and \} to indicate a right brace. The problem authoring language PG, however, uses this construction to indicated that text enclosed by \{ \} is to be interpreted by Perl, and the result substituted. Thus: when typing a brace in LaTex, use \lbrace or \rbrace.


Since backslashes have meaning in both Perl and LaTeX, a literal backslash should be typed as ~~ (a double tilde).