Difference between revisions of "LaTeX Tips And Traps"

From WeBWorK_wiki
Jump to navigation Jump to search
(Starting a tips and traps page for LaTeX input in PG problems)
 
m (added tag)
 
(2 intermediate revisions by one other user not shown)
Line 7: Line 7:
 
==Dollar Sign==
 
==Dollar Sign==
   
This procedure requires that the input code be valid Perl code. Since Perl uses the dollar sign '<code>$</code>' to indicate a (scalar) variable name, we cannot use the '<code>$</code>' sign in our LaTeX. Instead, use <code>\(</code> and <code>\)</code> to begin and end inline LaTeX math mode, and <code>\[</code> and <code>\]</code> to begin and end LaTeX display mode.
+
This procedure requires that the input code be valid Perl code. Since Perl uses the dollar sign '<code>$</code>' to indicate a (scalar) variable name, we cannot use the '<code>$</code>' sign in LaTeX mode. Instead, use <code>\(</code> and <code>\)</code> to begin and end inline LaTeX math mode, and <code>\[</code> and <code>\]</code> to begin and end LaTeX display mode. To print the dollar sign symbol, use ${DOLLAR} between BEGIN_TEXT and END_TEXT.
   
 
==Percent Sign==
 
==Percent Sign==
Line 20: Line 20:
   
 
Since backslashes have meaning in both Perl and LaTeX, a literal backslash should be typed as <code>~~</code> (a double tilde).
 
Since backslashes have meaning in both Perl and LaTeX, a literal backslash should be typed as <code>~~</code> (a double tilde).
  +
  +
[[Category:Authors]]

Latest revision as of 17:13, 16 June 2021

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.

Backslashes

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