Skip to main content
Chemistry LibreTexts

6.1: Text Coloring and Emphasis

  • Page ID
    555723
  • ​

    ​

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\dsum}{\displaystyle\sum\limits} \)

    \( \newcommand{\dint}{\displaystyle\int\limits} \)

    \( \newcommand{\dlim}{\displaystyle\lim\limits} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \(\newcommand{\longvect}{\overrightarrow}\)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\ket}[1]{\left| #1 \right>}\)
    \(\newcommand{\bra}[1]{\left< #1 \right|}\)
    \(\newcommand{\braket}[2]{\left< #1 \vphantom{#2} \right| \left. #2 \vphantom{#1} \right>}\)
    \(\newcommand{\braopket}[3]{\left< #1 \vphantom{#2}\vphantom{#3} \right| #2 \vphantom{#1}\vphantom{#3} \left| #3 \vphantom{#1}\vphantom{#2} \right>}\)
    \(\newcommand{\qmvec}[1]{\mathbf{\vec{#1}}}\)
    \(\newcommand{\op}[1]{\hat{\mathbf{#1}}}\)
    \(\newcommand{\expect}[1]{\langle #1 \rangle}\)
    \(\newcommand{\dfn}[1]{\emph{\textbf{#1}}}\)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)

    This page shows how to add visual emphasis using CSS-based styling that works in the PG 2.17 subset. Use this for terms like ABOVE/BELOW or NOT where color or bold weight prevents misreads.

    Use this page when: you need to highlight key words, numeric values, or label classes in matching or statement-based prompts. For general PGML layout controls, see Layout controls. For common CSS mistakes, see Common Mistakes and How to Fix Them.

    Why emphasize key information?

    Students often miss critical details in question statements, leading to common errors:

    • Reading the wrong value (pH 7.4 instead of pH 8.0)
    • Missing important qualifiers like NOT, LEAST, or MOST
    • Overlooking units or experimental conditions

    Visual emphasis helps students quickly locate critical values and focus on what matters. Even a small amount of color or size change can dramatically reduce misreading errors.

    Emphasis styles by use case

    Emphasis styles by use case: use case, style, css properties, and more.
    Use case Style CSS properties Example content
    Numeric values (pH, temperatures) Blue badge color:#0066cc; font-size:1.35em; font-weight:700; background-color:#e6f2ff; padding:0.1em 0.4em; border-radius:4px pH 7.4
    Key terms (hydrophobic, polar) Gold emphasis color:#997300; font-size:1.25em; font-weight:700 hydrophobic
    Negation (NOT, EXCEPT) Red warning color:#cc0000; font-size:1.3em; font-weight:700 NOT
    Multiple values (pKa lists) Monospace with background font-family:monospace; background-color:#f5f5f5; padding:0.2em 0.5em; border-radius:3px; font-size:1.1em 1.82, 6.00, 9.17

    CSS class approach (preferred)

    Define CSS classes once in HEADER_TEXT at the top of the problem, then reference them with PGML tag wrappers. This keeps styles in one place and reusable throughout the problem.

    HEADER_TEXT(MODES(TeX => '', HTML => <<'END_STYLE'));
    <style>
    .emph-data    { color:#0066cc; font-size:1.35em; font-weight:700;
                    background-color:#e6f2ff; padding:0.1em 0.4em; border-radius:4px; }
    .emph-term    { color:#997300; font-size:1.25em; font-weight:700; }
    .emph-warning { color:#cc0000; font-size:1.3em;  font-weight:700; }
    </style>
    END_STYLE
    
    BEGIN_PGML
    Which amino acid is predominantly charged at
    [<pH 7.4>]{['span', class => 'emph-data']}{['','']}?
    
    Which of the following is
    [<NOT>]{['span', class => 'emph-warning']}{['','']}
    a nucleotide?
    END_PGML
    

    The tag wrapper syntax is [<text>]{['span', class => 'class-name']}{['','']}. The first brace pair sets the HTML element and attributes; the second {['','']} closes the tag.

    Inline style approach

    If you only need emphasis in one place, you can use inline styles directly in the tag wrapper. This works but is harder to maintain when the same style appears in multiple places.

    BEGIN_PGML
    [<Important>]{['span', style => 'color:#b91c1c; font-weight:700;']}{['','']}
    END_PGML
    

    What does NOT work: TeX and MathJax color commands

    Do not use \color, \textcolor, or other TeX/MathJax color commands for text coloring in PGML. In this install, PGML escapes backslashes into tex2jax_ignore spans before MathJax processes them, so the TeX color commands never reach the math renderer.

    ## These all FAIL - do not use them ##
    [\color{#cc00cc}{\text{colored text}}]
    \(\color{#cc00cc}{\text{colored text}}\)
    $colored = "\color{red}{\text{warning}}";
    [$colored]
    

    Backslashes are escaped into <span class="tex2jax_ignore">\\</span> before MathJax runs, so the TeX commands are never processed. Use CSS styling instead.

    Passing HTML variables through PGML

    PGML tag wrappers are parsed at compile time. If you build HTML spans inside Perl variables, PGML will not re-parse them. Instead, pass them through using [$var]* so the HTML is not escaped.

    # Build the HTML span in the Setup section
    $label = "<span style='color:#0f766e; font-weight:700;'>ABOVE</span>";
    
    BEGIN_PGML
    Threshold: [$label]*
    END_PGML
    

    The trailing * tells PGML to pass the content through as raw HTML. Without it, the HTML tags are escaped and displayed as literal text.

    Font size guidelines

    Font size guidelines: size, level of emphasis, and when to use.
    Size Level of emphasis When to use
    1.1em Subtle Formulas, value lists, monospace data
    1.25em Moderate Key terms, qualitative descriptors
    1.35em Strong pH values, critical numeric data
    1.5em Maximum Rarely needed; only for prominent warnings

    Do not exceed 1.5em. Larger text becomes distracting and looks unprofessional.

    Color palette recommendations

    Color palette recommendations: color, hex value, and use case.
    Color Hex value Use case
    Blue #0066cc pH values, temperatures, concentrations
    Gold #997300 Key terms like hydrophobic, polar, most, least
    Red #cc0000 NOT, EXCEPT, CANNOT (use sparingly)
    Light blue bg #e6f2ff Data badge backgrounds behind blue text
    Light gray bg #f5f5f5 Subtle monospace backgrounds for value lists

    Avoid pure black (#000000) for emphasis, bright green or yellow (accessibility issues), and using more than two or three colors per question (visual clutter).

    Accessibility considerations

    Never rely on color alone to convey meaning. Combine color with at least one other method such as font size, font weight, or a background highlight so that colorblind users can still distinguish emphasized content. Aim for a minimum contrast ratio of 4.5:1 between text and background. The recommended palette above meets this threshold on white backgrounds (#0066cc = 8.6:1, #997300 = 5.2:1, #cc0000 = 5.9:1).

    Complete working examples

    pH question with blue badge (CSS class approach):

    HEADER_TEXT(MODES(TeX => '', HTML => <<'END_STYLE'));
    <style>
    .emph-ph { color:#0066cc; font-size:1.35em; font-weight:700;
               background-color:#e6f2ff; padding:0.1em 0.4em; border-radius:4px; }
    </style>
    END_STYLE
    
    $ph_value = list_random(6.0, 7.0, 7.4, 8.0);
    
    BEGIN_PGML
    Which amino acid is predominantly charged at
    [<pH [$ph_value]>]{['span', class => 'emph-ph']}{['','']}?
    
    [_]{$answer}
    END_PGML
    

    Negation question with red warning (variable approach):

    $not_emph = "<span style='color:#cc0000; font-size:1.3em; font-weight:700;'>NOT</span>";
    
    BEGIN_PGML
    Which of the following is [$not_emph]* a nucleotide?
    
    [_]{$answer}
    END_PGML
    

    Multiple emphasized elements (mixed data and term emphasis):

    HEADER_TEXT(MODES(TeX => '', HTML => <<'END_STYLE'));
    <style>
    .emph-data { color:#0066cc; font-size:1.25em; font-weight:700;
                 background-color:#e6f2ff; padding:0.1em 0.3em; border-radius:3px; }
    .emph-term { color:#997300; font-size:1.25em; font-weight:700; }
    </style>
    END_STYLE
    
    $compound = "glucose";
    $temp = "37 degrees C";
    
    BEGIN_PGML
    At [<[$temp]>]{['span', class => 'emph-data']}{['','']},
    what is the solubility of
    [<[$compound]>]{['span', class => 'emph-term']}{['','']}
    in water?
    
    [_]{$answer} g/L
    END_PGML
    

    Complete renderable problem with emphasis -- A full problem using CSS class emphasis to highlight a pH value in the question stem.

    ## TITLE('Amino acid charge at a given pH')
    ## DESCRIPTION
    ## Identify whether an amino acid side chain is charged
    ## at a specified pH, with the pH value visually emphasized.
    ## ENDDESCRIPTION
    ## KEYWORDS('amino acids','pH','emphasis','RadioButtons')
    ## DBsubject('Biochemistry')
    ## DBchapter('Amino Acids')
    ## DBsection('Charge')
    ## Date('2026-02-15')
    ## Author('Author name')
    ## Institution('Institution name')
    
    DOCUMENT();
    loadMacros(
    	"PGstandard.pl",
    	"PGML.pl",
    	"parserRadioButtons.pl",
    	"PGcourse.pl",
    );
    
    HEADER_TEXT(MODES(TeX => '', HTML => <<'END_STYLE'));
    <style>
    .emph-ph { color:#0066cc; font-size:1.35em; font-weight:700;
               background-color:#e6f2ff; padding:0.1em 0.4em;
               border-radius:4px; }
    </style>
    END_STYLE
    
    $rb = RadioButtons(
    	[ 'Positively charged', 'Negatively charged',
    	  'Neutral', 'Zwitterionic only' ],
    	'Positively charged',
    	labels        => 'ABC',
    	displayLabels => 1,
    );
    
    BEGIN_PGML
    The side chain of lysine has a pKa of approximately 10.5.
    
    At [<pH 7.4>]{['span', class => 'emph-ph']}{['','']},
    is the lysine side chain:
    
    [_]{$rb}
    END_PGML
    
    ENDDOCUMENT();
    

    Matching problem label colors

    When labels in matching problems need fixed colors by meaning (not by randomized position), build an HTML mapping in Perl and emit each label with * so PGML does not escape the spans. This keeps colors tied to the label text even when the display order is randomized.

    %answer_html = (
      'ionic bond'    => "<span style='color:#009900; font-weight:700;'>ionic bond</span>",
      'hydrogen bond' => "<span style='color:#e60000; font-weight:700;'>hydrogen bond</span>",
    );
    @answers_html = map { $answer_html{$_} || $_ } @answers;
    
    # In PGML, render each label with * to pass through HTML
    [$answers_html[$shuffle[0]]]*
    

    Common failure: missing the asterisk

    [$label]     # BROKEN - HTML is escaped, shows raw tags
    [$label]*    # CORRECT - asterisk prevents escaping
    

    If you see literal <span> tags in the rendered question, the most likely cause is a missing *. Always use [$var]* when the variable contains HTML.

    Best practices

    Do

    • Emphasize one to three key elements per question.
    • Use consistent colors for similar element types across your problem set.
    • Combine color with size or weight for accessibility.
    • Create emphasis variables in the Setup section, not inside PGML.
    • Use [$var]* to render HTML stored in Perl variables.
    • Prefer CSS classes defined in HEADER_TEXT over inline styles.

    Do not

    • Emphasize everything; it defeats the purpose.
    • Use more than three colors in one question.
    • Make text larger than 1.5em.
    • Use red for non-warning content.
    • Use TeX or MathJax color commands; they do not render in this install.
    • Forget the * in [$var]* when the variable contains HTML.

    This page titled 6.1: Text Coloring and Emphasis was last modified on Fri, 27 Feb 2026 15:37:56 GMT and is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Neil R. Voss.