File:  [LON-CAPA] / loncom / html / adm / help / tex / Authoring_Output_Tags.tex
Revision 1.27: download - view: text, annotated - select for diffs
Fri Jan 22 17:16:31 2021 UTC (3 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, version_2_11_X, HEAD
- Modify quotes for display of eval="on" web rendering of help file.
- Document (a) precedence of display attribute in algebra and m tags,
  (b) determination of default math display engine if no attribute.

\label{Authoring_Output_Tags}


This group of tags generates useful output. 

\begin{itemize}
\item \textbf{algebra}\index{algebra}\index{format algebra}: Typesets algebraic expressions
\begin{verbatim}
<algebra>2x^y+sqrt(3/x^2)</algebra>
\end{verbatim}
Expressions are displayed using the math expression display mechanism for the current context.  The default is to use
the display mechanism the user has selected in preferences. This can be overriden by setting the \textbf{display} attribute for the tag. See the section below concerning the $<$m$>$ tag for more information on how the default is set and on the display attribute.

Recognized functions are all trigonometric functions, and the following:
exp, abs, logten, log, ln, sqrt, sgn, step, fact, int, lim, funX.
\item \textbf{chem}\index{chem}\index{format reaction}: Typesets chemical equation :
\begin{verbatim}
  <chem>O2 + 2H2 -> 2H2O</chem>
\end{verbatim}
will be rendered:
$\mathrm{O_2} + 2\,\mathrm{H_2} \to 2\,\mathrm{H_2O}$

\textbf{Syntax Description}
\begin{itemize}
\item Reactants are separated from products by `\texttt{->}'.
\item Individual reactants and products are separated by `\texttt{  +}' (leading space is obligatory).
\item Numbers preceding the first symbol of a chemical specie are considered to be stoichiometric coefficients.
\item Numbers appearing after the first symbol of a chemical specie are considered to be subscripts.
\item Superscripts are initialized by `\texttt{\^{}}' and terminated by a space.
\item Ionic charges are superscripts composed of a number followed by a sign (i.e. `\texttt{\^{}2+}').
\end{itemize}

\textbf{More examples}
\begin{itemize}
\item $\mathrm{Ca}(\mathrm{NO}_3)_2$ is written as:\\
\texttt{Ca(NO3)2}
\item $\mathrm{OH}^- + \mathrm{H_3O}^+ \to 2\mathrm{H_2O}$ is written as:\\
\texttt{OH\^{}- + H3O\^{}+ -> 2H2O}
\item $[\mathrm{Co}(\mathrm{H_2O})_6]^{2+} + 4\mathrm{Cl}^- \to [\mathrm{CoCl_4}]^{2-} + 6\mathrm{H_2O}$ is written as:\\
\texttt{[Co(H2O)6]\^{}2+ + 4Cl\^{}- -> [CoCl4]\^{}2- + 6H2O}
\item $^3_1\mathrm{H} + ^2_1\mathrm{H} \to ^4_2\mathrm{He} + ^1_0\mathrm{n}$ is written as:\\
\texttt{\^{}3 1H + \^{}2 1H -> \^{}4 2He + \^{}1 0n}
\end{itemize}

\item \textbf{num}\index{num}\index{format number}: Typesets a number formatted in scientific notation, fixed point, fixed point with commas, fixed point with commas and dollar sign, or in significant digits. 
\begin{verbatim}
  <num format="2E">31454678</num> results in 3.15 x 10^7
  <num format="2f">31454678</num> results in 31454678.00
  <num format="4g">31454678</num> results in 3.145 x 10^7
  <num format="4g">314.54678</num> results in 314.5
  <num format=",2f">31454678</num> results in 31,454,678.00
  <num format="$2f">31454678</num> results in $31,454,678.00
  <num format="2s">31454678</num> results in 31000000
  <num format=",2s">31454678</num> results in 31,000,000
\end{verbatim}
\item \textbf{parse}\index{parse}: to display the parsed view of a variable's
contents
\begin{verbatim}
  <script type="loncapa/perl">
   $table='<table>';
   for ($i=1;$i<=10;$i++) {
      $table.='<tr><td>'.$i.'</td><td>'.&random(1,10,1).'</td></tr>';
   }
   $table.='</table>';
  </script>
  <parse>$table</parse>
\end{verbatim}

\item \textbf{standalone}\index{standalone}: Everything in between the
start and end tag is shown only on the web and only if the resource
is not part of a course. 
\item \textbf{displayduedate}\index{displayduedate}: This will insert the
current due date if one is set in the document. It is generated to
be inside a table of 1x1 elements.  The displayduedate tag accepts
The following attributes:
   \begin{description}
      \item{style=``plain'' }  Makes the due date appear without any boxing.
                               If the parameter value is other than  ``\emph{plain}'',
			       or if the \textbf{style} parameter is omitted, the
			       due date will be displayed within a box.
      \item{format=``fmt\_string''} 
                              Allows you to control the format of the due date.
			      ``\emph{fmt\_string}'' is an arbitrary string that
			      can contain any of the following formatting items:
			      \begin{description}
			         \item{\%a} Replaced by the abbreviated weekday
				            name according to the current locale.
			         \item{\%A} Replaced by the full weekday name 
				           according to the current locale.
		                 \item{\%b} The abbreviated month name according to the
				            current locale.
			         \item{\%B} The full month name according to the
                                            current locale.
			         \item{\%c} The preferred date and time representation
				            for the current locale (the default format
					    string is just this).
			         \item{\%C} The century number as a two digit integer
				 \item{\%d} The day of the month as a decimal number.
				            Leading zeroes are shown for single digit day numbers.
				 \item{\%D} Equivalent to \%m/\%d/\%y  
				 \item{\%e} Like \%d but a leadnig zero is replaced by a space.
				 \item{\%F} Equivalent to \%Y-\%m-\%d
				 \item{\%G} The four digit year number.
				 \item{\%g} The two digit year numbger.
				 \item{\%H} The hour as a two digit number in the range 00 thorugh 23.
				 \item{\%I} The hour as a two digit number in the range 00 through 12.
				 \item{\%j} The day your the year in the range 001 through 366.
				 \item{\%k} The hour (24 hour clock), single digits are preceded by a blank.
				 \item{\%l} Like \%k but using a 12 hour clock.
				 \item{\%m} The month as a two digit decimal number in the range 01 through 12.
				 \item{\%M} The minute as a two digit decimal number in the range 00 through 59.
				 \item{\%n} A newline character.
				 \item{\%p} AM or PM depending on the time value.
				 \item{\%P} am or pm.
				 \item{\%r} The time in am or pm notation.
				 \item{\%R} Time in 24 hour notatinon (\%H:\%M).  See also \%T below.
				 \item{\%s} Number of seconds since midnight of January 1, 1970.
				 \item{\%S} The second as a decimal number int the range 00 through 59.
				 \item{\%t} A horizontal tab character.
				 \item{\%T} The time in 24 hour notation (\%H:\%M:\%S).
				 \item{\%u} Day of the week as a decimal number with Monday as 1.
				 \item{\%U} The week number of the current year in the range 00 through 53.
				            Week 1 is the week containing the first Sunday of the year.
				 \item{\%V} Same as \%U but week 1 is the first week with at least 4 days,
				            with Monday being the first day of a week.
			         \item{\%w} Day of the week as a decimal integer in the range 0 through 7, Sunday is 0.
				 \item{\%W} Week number of the current year in the range 00 through 53, where
				            the first Monday of the year is the first day of week 01.
			         \item{\%x} The preferred date notation in the current locale without the time.
				 \item{\%X} The preferred time notation in the current locale without the date.
				 \item{\%y} The year as a decimal number without the century (range 00 through 99).
				 \item{\%Y} The year as a decimal number including the century.
				 \item{\%\%} A \% character.
				 \item{\%+} Date and time in the form returned by the Unix date command.
			      \end{description}
   \end{description}
\item \textbf{displaytitle}\index{displaytitle}: This will insert the title
of the problem from the metadata of the problem. Only the first \textbf{displaytitle}
in a problem will show the title; this allows clean usage of \textbf{displaytitle}
in LON-CAPA style files.

\item \textbf{window}\index{window}: This creates a link that when clicked shows the intervening information in a pop-up window. By default the window will be 500 pixels wide and 200 pixels tall, and the link text will be a superscript * (so as to look like a footnote). These can be changed using the attributes

\begin{itemize}
\item \textbf{width} controls the starting width of the popup window
\item \textbf{height} controls the starting height of the popup window
\item \textbf{linktext} the text that should appear as the link that causes the creation of the window
\item \textbf{printtext} the text that should appear instead of a footnote when printed
\end{itemize}

When printing, the included text will get turned into a real footnote.

\item \textbf{windowlink}\index{windowlink}: This creates a link to a resource that comes up in a pop-up window. The link will be the intervening information
between the start and the end tag. By default the window will be 500 pixels wide and 200 pixels tall.

\begin{itemize}
\item \textbf{width} controls the starting width of the popup window
\item \textbf{height} controls the starting height of the popup window
\item \textbf{href} the address
\end{itemize}

\item \textbf{togglebox}\index{togglebox}: This creates a toggling box that can be clicked open and close.

\begin{itemize}
\item \textbf{heading} heading text of the box, by default no heading
\item \textbf{headerbg} background color of the header, by default white
\item \textbf{showtext} the text that appears to make the box visible, by default the translation of `show'
\item \textbf{hidetext} the text that appears to hide the box again, by default the translation of `hide'
\end{itemize}

When printing, the included text will be rendered in a visible box.


\item \textbf{m}\index{m}\index{equations}: The inside text is \LaTeX{}, and is converted
to HTML (or MathML) on the fly. The default is to convert
to the display mechanism that the user has selected in preferences. This can be
overriden by setting the attribute \textbf{display} to one of
``\textbf{tth}'', ``\textbf{mimetex}'' or ``\textbf{mathjax}'' which
will force a specific display mechanism. Note that the ``\textbf{jsmath}'' display is deprecated today, and MathJax is used instead when it is specified.  If a display attribute is not included, the display mechanism is determined in the following order, with the first one set being the one in effect:
\begin{enumerate}
\item In course context: Course-wide default set by Course Coordinator via Settings $>$ Course Settings $>$ Display of resources $>$ Force use of a specific math rendering engine
\item User's own personal preference set by the user hovering over the user's name at top left of a LON-CAPA page, and selecting Preferences $>$ Math display settings
\item Domain default set by a Domain Coordinator 
\item System default set for the LON-CAPA version installed on the server (tth in 2.11 and earlier, mathjax in 2.12).
\end{enumerate}

The contents of \texttt{<m> </m>} are interpreted as LaTeX outside math environment, which is why using \texttt{<m>\$ \$</m>} is needed to switch to the LaTeX math environment. However, the ``\textbf{mathjax}'' display (which is used by default in recent versions of LON-CAPA) interprets all the contents of \texttt{<m> </m>} as math, and does not support non-math LaTeX. For content to work well with all the display mechanisms, it is therefore important to never use non-math LaTeX for web targets. Even purely for printing, it is better to avoid using non-math LaTeX, as the printing mechanism might use HTML instead of LaTeX in the future.

If you want variables inside of this tag to be evaluated before the
tex gets converted, then use eval=``on'' \index{eval=on}. For
example,  \texttt{<m eval=''on''>\$ \$eqn \$</m>},
will evaluate the variable \$eqn first and then use the
display mechanism.  Anytime you use a variable inside of the m tag,
you will want to set eval to on.

For example, put the following in a script in the resource:

\texttt{\$eqn = "\$a+\$b";}

\texttt{\$eqn =~ s/\textbackslash{}+-/-/g;}

and in a text area, you can type:

\texttt{<m eval=''on''>\$ \$eqn \$</m>}

You will get the equation rendered with no +-, no matter what value
\$b may take on.


\item \textbf{lm}\index{lm}\index{equations}: This is another way to input math, which does not require
knowing \LaTeX{}.
The lm syntax describes mathematical operations rather than appearance (as opposed to LaTeX, which describes how the math should appear). Display is the same when the math operations are the same, for instance 2*(x) will be displayed just like 2x. One advantage to that system is that math will be displayed in a consistent way, even when written by several authors. The drawback is that display cannot be chosen precisely.
Eventually, this syntax will also be used to evaluate \texttt{<formularesponse>} (it is already used for the real-time preview).

\begin{description}
\item[Spaces]~\\
    Spaces are always ignored.

\item[Decimal separators and function parameter separators]~\\
    To keep compatible with previous \texttt{<formularesponse>} syntax, only ``.'' can be used as a decimal separator, and ``,'' is used to separate function and vector/matrix parameters.
    
\item[Variables and constants]~\\
    Variable names and constant names are used directly, without any special character before. They are displayed in italics.
    
\item[Units]~\\
    Unit names are used directly. They are displayed with a straight font. LON-CAPA has a list of known units and a list of known constants to differentiate them in units mode.
    
\item[Parenthesis]~\\
    Parenthesis can be used to specify evaluation order. They are only displayed when necessary.
    
\item[Operators]~\\
    arithmetic: \texttt{+ - * / \^{}}\\
    factorial: \texttt{!}\\
    relational: \texttt{= \# < <= >= >}\\
    units: \texttt{`}\\
    Example: \texttt{2`m + 3`m = 5`m}\\
    scalar product for vectors, multiplication for matrices: \texttt{.}\\

\item[Implicit operators]~\\
    \texttt{*} and \texttt{`} are implicit.

    The parser will try to guess which operator is missing whenever possible. The choice between * and ` depends on the mode for interpreting equations.

    Example: \texttt{2c+3m/s} is understood in unit mode to be \texttt{2*c + 3`(m/s)}. In symbolic mode, it would be interpreted \texttt{2*c + (3*m)/s} (m and s being variables).
    
\item[Functions]~\\
    Functions use the syntax \texttt{f(a,b)}.

        basic:

        \quad \texttt{sqrt(x)}, \texttt{abs(x)}, \texttt{exp(x)=e\^{}x}, \texttt{factorial(x)=x!}

        binomial (displayed like a vector):

        \quad \texttt{binomial(n,p)=n!/(p!*(n-p)!)}

        sum and product (requiring symbolic mode):

        \quad \texttt{sum(f(x),x,x1,x2)}, \texttt{product(f(x),x,x1,x2)}

        differential, integral, limit:

        \quad \texttt{diff(expr,x,n)}, \texttt{integrate(expr,x,a,b)}, \texttt{limit(expr,x,val,dir)}

\item[Vectors and matrices]~\\
    Vectors and matrices are defined with square brackets. A matrix is made of a list of row vectors.

        vectors: \texttt{[1,2,3]}\\
        matrices: \texttt{[[1,2],[3,4]]}

\item[Sets]~\\
    Sets are defined with curly brackets: \texttt{\{1,2,3\}}

        union: \texttt{union(\{1,2\},\{1,3\}) = \{1,2,3\}}\\
        intersection: \texttt{intersection(\{1,2\},\{1,3\}) = \{1\}}
    
\end{description}


\item \textbf{randomlabel}\index{randomlabel}: This shows a specified image
with images or text labels randomly assigned to a set of specific
locations. Those locations may also have values assigned to them.
A hash is generated that contains the mapping of labels to locations,
labels to values, and locations to values. Example: \begin{verbatim}

 <randomlabel bgimg="URL" width="12" height="45" texwidth="50">
    <labelgroup name="GroupOne" type="image">
      <location x="123" y="456" value="10" />
      <location x="321" y="654" value="20" />
      <location x="213" y="546" value="13" />
      <label description="TEXT-1">IMG-URL</label>
      <label description="TEXT-2">IMG-URL</label>
      <label description="TEXT-3">IMG-URL</label>
    </labelgroup>
    <labelgroup name="GroupTwo" type="text">
      <location x="12" y="45" />
      <location x="32" y="65" />
      <location x="21" y="54" />
      <label>TEXT-1</label>
      <label>TEXT-2</label>
      <label>TEXT-3</label>
    </labelgroup>
   </randomlabel>
    
\end{verbatim}

 Possible attributes are:

\begin{itemize}
\item \textbf{bgimg}\index{bgimg}: Either a fully qualified URL for an
external image or a LON-CAPA resource. It supports relative references
(../images/apicture.gif). The image must either be a GIF or JPEG.
\item \textbf{width}\index{width}: The width of the image in pixels.
\item \textbf{height}\index{height}: The height of the image in pixels.
\item \textbf{texwidth}\index{texwidth}: The width of the image in millimeters.
\end{itemize}

\item \textbf{problemtype}\index{problemtype}: This tag allows you to show or hide output based on what the problem-type parameter is set to in the course. For example: \begin{verbatim}
<problemtype mode="show" for="exam,survey">
  <startouttext />
  The formula for the circumference of a circle is 2*pi*r
  <endouttext />
</problemtype>
\end{verbatim}
Will only show the output text when the problem is set to the type of exam or survey in the course.  The attribute for mode can be set to show or hide.  The attribute for for can be problem, exam, survey, or practice.

\end{itemize}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>