Skip to main content
Chemistry LibreTexts

6.5: Randomized Matching Problems

  • Page ID
    555725
  • ​

    ​

    \( \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 covers modern matching problems using PopUp widgets and two-column layouts. It also explains the one case where MODES(HTML => ...) is required: wrapper HTML that must be emitted from inside Perl eval blocks that build dynamic HTML with join().

    Use this page when: you need a two-column matching layout with consistent labels and randomized ordering. For basic matching with PopUp dropdowns, see Matching.

    When to use matching vs other question types

    Matching problems work best for:

    • Definitions: Match terms with their meanings (e.g., genotype vs phenotype)
    • Associations: Connect related concepts (e.g., enzyme names with their substrates)
    • Component identification: Link structures to functions (e.g., organelles to their roles)
    • Classification: Match examples to categories (e.g., bond types to molecular scenarios)

    Not ideal for

    • Pure memorization with no conceptual pairing
    • Sequence ordering (use drag-and-drop or ordered list instead)
    • True/false evaluation of statements (use RadioButtons per statement, see Randomized MC True and False Statements)

    Typical problem sizes: 4-8 pairs work well. Fewer than 4 is too easy; more than 8 becomes cognitively overwhelming and increases guessing.

    PopUp widgets for matching

    Use PopUp widgets from parserPopUp.pl to create dropdown menus in the left column. Note that DropDown is a PG 2.18+ macro and is not available in the PG 2.17 subset used by ADAPT/renderer.

    Widget creation pattern

    loadMacros(
      "PGstandard.pl",
      "PGML.pl",
      "parserPopUp.pl",
      "PGcourse.pl",
    );
    
    # Define choices (labels A, B, C, D for 4 answers)
    my @choices = ('A', 'B', 'C', 'D');
    
    # Define correct answers (mapped to choices)
    my @correct_answers = ('B', 'D', 'A', 'C');  # Correct letter for each question
    
    # Create PopUp widgets
    my @answer_dropdowns = map { PopUp(\@choices, $correct_answers[$_]) } 0 .. $#correct_answers;
    

    How shuffle arrays work

    Use the shuffle() function to randomize the order of right-column answers while maintaining correct left-right mapping:

    my @questions = (
      'Two oxygen atoms share electrons equally',
      'Sodium transfers an electron to chlorine',
      'Partial charges on C-O bond',
      'O-H bond attracted to nearby C=O',
    );
    
    my @answers = (
      'non-polar covalent bond',
      'ionic bond',
      'polar covalent bond',
      'hydrogen bond',
    );
    
    # Shuffle the right column
    my @shuffle = shuffle(scalar(@answers));  # Returns a permutation [0..3]
    
    # Now answers appear in shuffled order, but @shuffle maps them back to originals
    

    Answer evaluation in PGML

    In the left column, use [_]{$answer_dropdowns[$i]} to insert each PopUp widget. The student selects a letter from the dropdown, and WeBWorK checks it against the correct answer stored in the widget.

    Two layout patterns: When MODES is needed

    There are two ways to build matching layouts: with wrapper tags directly in PGML (preferred), or with MODES when wrapper HTML must be emitted from inside Perl eval blocks.

    Pattern 1: Wrapper tags directly in PGML (preferred)

    If you can write the wrapper <div> tags directly in PGML, do that. This avoids MODES entirely and is easier to read and maintain.

    BEGIN_PGML
    Match each molecular scenario with its bond type.
    
    <div class="two-column">
    <div>
    [@ join("\n\n", map {
      '[_]{$answer_dropdowns[' . $_ . ']} '
        . '*' . ($_ + 1) . '.* '
        . $questions[$_]
    } 0 .. $#questions) @]**
    </div>
    
    <div>
    [@ join("\n\n", map {
      '*' . chr(65 + $_) . '.* '
        . $answers[$shuffle[$_]]
    } 0 .. $#answers) @]**
    </div>
    </div>
    END_PGML
    

    In this pattern, the <div class="two-column"> wrapper is written directly in PGML. The join() expressions build the content for each column, and PGML processes everything correctly without needing MODES.

    Pattern 2: MODES when wrapper must be in eval block (required in specific cases)

    Use MODES(HTML => ...) only when the wrapper tags must be built inside a Perl eval block, such as when the wrapper and content are created together in a single Perl variable. Without MODES, the wrapper HTML gets escaped by PGML and the layout collapses to a single column.

    # Build left column HTML
    my $left_html = join("\n\n", map {
      '[_]{$answer_dropdowns[' . $_ . ']} '
        . '*' . ($_ + 1) . '.* '
        . $questions[$_]
    } 0 .. $#questions);
    
    # Build right column HTML
    my $right_html = join("\n\n", map {
      '*' . chr(65 + $_) . '.* '
        . $answers[$shuffle[$_]]
    } 0 .. $#answers);
    
    # Wrap with MODES because wrapper tags are in eval block
    my $columns = MODES(HTML => "<div class='two-column'><div>\n$left_html\n</div><div>\n$right_html\n</div></div>");
    
    BEGIN_PGML
    [$columns]*
    END_PGML
    

    In this pattern, the wrapper <div> tags are built inside the Perl variable $columns, so MODES is required to prevent PGML from escaping them.

    Pattern 3: Inline MODES for wrapper segments (alternative)

    You can also emit wrapper HTML segments using inline MODES calls between join() expressions:

    BEGIN_PGML
    Match each molecular scenario with its bond type.
    
    [@ MODES(HTML => '<div class="two-column"><div>') @]*
    [@ join("\n\n", map { ... } 0 .. $#questions) @]**
    [@ MODES(HTML => '</div><div>') @]*
    [@ join("\n\n", map { ... } 0 .. $#answers) @]**
    [@ MODES(HTML => '</div></div>') @]*
    END_PGML
    

    This is a middle-ground approach. Use it when you want the wrapper segments close to the content but cannot write them directly as plain HTML in PGML.

    Why MODES is needed (technical explanation)

    PGML parses content once and escapes HTML tags for safety. When wrapper <div> tags are inside Perl variables or eval blocks, PGML sees them as data to be escaped, not markup. Using MODES(HTML => ...) tells PG to emit the HTML directly without escaping, but only in HTML output mode (not TeX/PDF mode).

    What happens if you forget MODES: The wrapper <div> tags appear as literal text in the rendered problem (e.g., &lt;div class="two-column"&gt;) or are stripped entirely, causing the layout to collapse to a single column.

    CSS styling for two-column layout

    Use HEADER_TEXT with flexbox CSS to create a responsive two-column layout. This style works across devices and wraps to a single column on narrow screens.

    Recommended flexbox style

    HEADER_TEXT(MODES(HTML => <<'END_STYLE'));
    <style>
    .two-column {
      display: flex;
      flex-wrap: wrap;
      gap: 2rem;
      align-items: flex-start;
      justify-content: space-evenly;
    }
    .two-column > div {
      flex: 1 1 40%;
      min-width: 250px;
    }
    </style>
    END_STYLE
    

    CSS property explanations

    • display: flex; - Creates a flexible container for the two columns
    • flex-wrap: wrap; - Allows columns to wrap on narrow screens (mobile-friendly)
    • gap: 2rem; - Adds spacing between columns
    • align-items: flex-start; - Aligns columns to the top (not vertically centered)
    • justify-content: space-evenly; - Distributes horizontal space evenly
    • flex: 1 1 40%; - Each column takes ~40% width, can grow or shrink
    • min-width: 250px; - Prevents columns from becoming too narrow

    Alternative alignment options

    • align-items: center; - Vertically center columns (use if heights differ significantly)
    • justify-content: space-between; - Push columns to edges with space between
    • gap: 1rem; - Reduce spacing for compact layouts

    Colored labels for fixed label-to-meaning mapping

    When answer labels need fixed colors by meaning (not by position), build an HTML mapping in Perl and emit the labels with the [$var]* pattern (trailing asterisk required) so PGML does not escape the <span> tags.

    Building the color mapping

    # Label -> HTML mapping (fixed colors by meaning)
    my %answer_html = (
      'polar covalent bond' => '<span style="color:#00b3b3; font-weight:700;">polar covalent bond</span>',
      'non-polar covalent bond' => '<span style="color:#b3b300; font-weight:700;">non-polar covalent bond</span>',
      'ionic bond' => '<span style="color:#009900; font-weight:700;">ionic bond</span>',
      'hydrogen bond' => '<span style="color:#e60000; font-weight:700;">hydrogen bond</span>',
    );
    
    # Build colored HTML labels array
    my @answers_html = map { $answer_html{$_} } @answers;
    

    Emitting colored labels in PGML

    In the right-column join() expression, use [$answers_html[$shuffle[$_]]]* with the trailing asterisk to pass through the HTML without escaping:

    [@ join(
      "\n\n",
      map {
        '*' . chr(65 + $_) . '.* '
          . '[$answers_html[$shuffle[' . $_ . ']]]*'
      } 0 .. $#answers
    ) @]**
    

    Why the trailing asterisk is required

    Without the trailing *, PGML escapes HTML tags for safety. Using [$var]* tells PGML to pass through the variable's content as raw HTML. This keeps colors tied to label meaning even when the order is randomized. For more on this pattern, see Text Coloring and Emphasis.

    Biology examples

    Example 1: Chemical bond types

    Scenario: Match molecular interactions with the correct bond type. Use colored labels to distinguish bond types visually.

    my @questions = (
      'Two oxygen atoms share electrons equally',
      'Sodium transfers an electron to chlorine',
      'Partial charges on C-O bond',
      'O-H bond attracted to nearby C=O',
    );
    
    my @answers = (
      'non-polar covalent bond',
      'ionic bond',
      'polar covalent bond',
      'hydrogen bond',
    );
    
    my @shuffle = shuffle(scalar(@answers));
    
    my %answer_html = (
      'non-polar covalent bond' => '<span style="color:#b3b300; font-weight:700;">non-polar covalent bond</span>',
      'ionic bond' => '<span style="color:#009900; font-weight:700;">ionic bond</span>',
      'polar covalent bond' => '<span style="color:#00b3b3; font-weight:700;">polar covalent bond</span>',
      'hydrogen bond' => '<span style="color:#e60000; font-weight:700;">hydrogen bond</span>',
    );
    my @answers_html = map { $answer_html{$_} } @answers;
    

    Note: Fixed colors ensure that "hydrogen bond" is always red, regardless of randomization, helping students build consistent mental associations.

    Example 2: Pathway components matched to functions

    Scenario: Match glycolytic enzymes with their specific reactions in the pathway.

    my @questions = (
      'Converts glucose-6-phosphate to fructose-6-phosphate',
      'Phosphorylates fructose-6-phosphate (rate-limiting step)',
      'Splits fructose-1,6-bisphosphate into two 3-carbon sugars',
      'Converts phosphoenolpyruvate to pyruvate (ATP-generating step)',
    );
    
    my @answers = (
      'phosphoglucose isomerase',
      'phosphofructokinase-1',
      'aldolase',
      'pyruvate kinase',
    );
    
    my @choices = ('A', 'B', 'C', 'D');
    my @shuffle = shuffle(scalar(@answers));
    
    my @correct_answers = map { $choices[$shuffle[$_]] } 0 .. $#questions;
    my @answer_dropdowns = map { PopUp(\@choices, $correct_answers[$_]) } 0 .. $#questions;
    

    Note: This example demonstrates function-to-enzyme matching without colors, focusing on conceptual pairing for pathway memorization.

    Example 3: Genetics terminology matched to definitions

    Scenario: Match genetics terms with their formal definitions.

    my @questions = (
      'Observable physical characteristic',
      'Genetic makeup at a locus',
      'Alternative form of a gene',
      'Physical location of a gene on a chromosome',
    );
    
    my @answers = (
      'phenotype',
      'genotype',
      'allele',
      'locus',
    );
    
    my @choices = ('A', 'B', 'C', 'D');
    my @shuffle = shuffle(scalar(@answers));
    
    my @correct_answers = map { $choices[$shuffle[$_]] } 0 .. $#questions;
    my @answer_dropdowns = map { PopUp(\@choices, $correct_answers[$_]) } 0 .. $#questions;
    

    Note: This is a pure definition-matching problem, ideal for introducing formal terminology early in a genetics unit.

    Common failures and fixes

    Failure 1: Forgot trailing asterisk on colored labels

    Symptom: Raw <span> tags appear in the rendered problem instead of colored text.

    Cause: Used [$var] instead of [$var]*, so PGML escaped the HTML for safety.

    Fix: Always use [$answers_html[$shuffle[$_]]]* with the trailing asterisk to pass through HTML.

    Prevention: Check all variable interpolations that contain HTML. The rule is: [$var]* for HTML, [$var] for plain text.

    Failure 2: Used MODES for everything

    Symptom: Code works but is unnecessarily complex and harder to maintain.

    Cause: Wrapped every HTML snippet in MODES, including cases where wrapper tags could be written directly in PGML.

    Fix: Use Pattern 1 (wrapper tags directly in PGML) whenever possible. Only use MODES when the wrapper HTML is inside Perl eval blocks.

    Prevention: Ask: "Can I write these <div> tags directly in PGML?" If yes, do that.

    Failure 3: Shuffle array index mismatch

    Symptom: Wrong answers are marked correct. Dropdown selections don't map to the displayed right-column labels.

    Cause: Used $shuffle[$_] incorrectly in left column or right column, breaking the mapping.

    Fix: Verify that left column uses $answer_dropdowns[$_] (no shuffle) and right column uses $answers[$shuffle[$_]] (with shuffle).

    Prevention: Test with problemSeed values that produce different shuffle orders. Check that correct answers remain correct.

    Failure 4: PopUp choices don't match answer labels

    Symptom: Dropdown shows letters that don't appear in the right column, or vice versa.

    Cause: Used different @choices arrays for PopUp creation and right-column labels.

    Fix: Use the same @choices array (e.g., ('A', 'B', 'C', 'D')) for both PopUp widget creation and right-column label generation.

    Prevention: Define @choices once at the top of setup and reference it everywhere.

    Failure 5: Layout collapses to single column

    Symptom: Both columns stack vertically instead of appearing side-by-side.

    Cause: Wrapper <div> tags were built in Perl without MODES, so PGML escaped them.

    Fix: Either move wrapper tags directly into PGML (Pattern 1) or wrap them with MODES(HTML => ...) (Pattern 2).

    Prevention: If wrapper HTML is inside a Perl variable, use MODES. If it's directly in PGML, no MODES needed.

    Creating matching banks with YAML

    Instead of writing each matching problem by hand, you can define a bank of matching pairs in a YAML file and use a generator script to produce PGML files automatically. This workflow separates content authoring from code, making it easier for instructors to contribute questions without editing Perl.

    File naming convention

    Use filenames that are readable to instructors and map naturally to course chapters. Follow the pattern: topic prefix + plain-English descriptor.

    • enzymes_basics.yml -- enzyme classes matched to reaction types
    • senses_receptor_types.yml -- receptor types matched to sensory modalities
    • metabolism_pathway_components.yml -- pathway enzymes matched to functions

    Avoid deep jargon in filenames (keep jargon inside the YAML content). Future-you should know what the bank covers without opening the file.

    YAML file structure

    Every YAML bank requires four top-level keys that describe what students are matching:

    YAML file structure: key, purpose, and example.
    Key Purpose Example
    key description Singular label for the left column enzyme class
    keys description Plural label for the left column enzyme classes
    value description Singular label for the right column reaction type
    values description Plural label for the right column reaction types

    The fifth required key is matching pairs, which holds the actual content (see next section).

    Matching pairs format

    Under matching pairs, each key maps to a list of one or more values. Each key is a left-column concept; each value is a right-column definition or function.

    matching pairs:
      Kinase:
        - Adds a phosphate group to a substrate (phosphorylation)
        - Transfers a phosphate group to a molecule
      Phosphatase:
        - Removes a phosphate group from a substrate (dephosphorylation)
        - Catalyzes phosphate removal from a molecule
    

    Each key must map to a YAML list, even if there is only one value. For each generated question, the generator picks one value per key at random.

    Same concept, different phrasing

    The most important quality rule: put synonyms and equivalent statements under one key as multiple values. Do not split a single concept across multiple keys (that turns synonyms into trick questions).

    This makes banks feel fresh without changing what you are assessing. Students see one wording per key in any single question, but across different generated questions the bank naturally rotates through alternate wordings.

    matching pairs:
      Protease:
        - Breaks peptide bonds in proteins
        - Hydrolyzes peptide bonds
      Ligase:
        - Joins two molecules by forming a new bond (often using ATP)
        - Catalyzes bond formation to link molecules
    

    Excluding confusable pairs

    If two keys are too similar (or their values are too easy to mix up), use exclude pairs so they never appear together in the same question:

    exclude pairs:
      - [Coenzyme, Cofactor]
      - [competitive inhibitor, non-competitive inhibitor]
    

    Use exclude pairs sparingly, only for classic confusions where students can reasonably know both terms yet still mix them up under time pressure. Do not exclude pairs just because two terms are related -- that can remove the learning objective.

    Replacement rules for formatting and color

    The replacement_rules key defines simple search-and-replace substitutions applied after question text is constructed. This is commonly used for highlighting phrases with color or ensuring consistent typography.

    replacement_rules:
      releases&nbsp;energy: "<span style='color: #e60000;'>releases&nbsp;energy</span>"
    

    Colors are assigned deterministically: the same prompt set gets the same colors on every run. If any prompt already contains HTML color markup, automatic coloring is disabled for the entire question so author-chosen colors are preserved.

    Optional metadata keys

    The generators ignore unknown top-level keys, so you can add author-facing metadata for long-term maintenance:

    • topic -- short label (e.g., phototransduction)
    • learning_objective -- one sentence (e.g., Trace the cGMP pathway in rods)
    • source -- textbook or chapter reference
    • items to match per question -- how many pairs appear per question (default 5)

    Generating PGML files from YAML

    The yaml_match_to_pgml.py script reads a YAML bank and produces matching-problem PGML files. The generated files follow the same PopUp widget and MODES wrapper patterns described earlier in this chapter.

    What the generator does

    • Reads the YAML matching pairs and descriptions
    • Selects one value per key at random (rotating through phrasings across runs)
    • Applies replacement rules for color and formatting
    • Unescapes HTML entities (named and numeric) into Unicode for rendering without MathJax
    • Converts <sub>/<sup> tags into Unicode subscripts/superscripts
    • Outputs PGML files using the two-column flexbox layout with PopUp widgets

    The default output uses inline HTML spans for replacement-rule colors. Use --no-color to disable styling.

    Quality checks for matching banks

    Before shipping a new matching set, run through these checks:

    Quality checks for matching banks: check and what to look for.
    Check What to look for
    Single learning objective per key Each key should test one concept, not a bundle of related facts
    Parallel grammar All values should use the same grammatical form (all noun phrases, or all full sentences)
    Similar value length If one answer is much longer than others, students use length as a hint
    No keyword cues If a prompt contains a distinctive word, do not repeat it in the matching value
    Distinct values across keys If multiple keys could match the same value text, students are guessing
    Accessibility Do not rely on color alone to convey meaning; use color as an accent

    Difficulty control

    Adjust the difficulty of matching questions by changing the number of items and the phrasing style:

    • Easier: Use direct definitions and unique vocabulary. Set items to match per question: 3 or 4 for fewer items per question.
    • Harder: Use mechanism or consequence phrasing instead of definitions. Include more similar terms in the bank, then use exclude pairs for the worst confusions.

    Copy/paste YAML example: enzyme classes

    This is a complete, working YAML file for a matching bank. Copy it as a starting point for new banks.

    #YAML file for Matching Questions
    topic: enzymes_basics
    learning_objective: Match enzyme classes to what they do.
    
    items to match per question: 5
    
    key description: enzyme class
    keys description: enzyme classes
    
    value description: reaction type
    values description: reaction types
    
    matching pairs:
      Kinase:
        - Adds a phosphate group to a substrate (phosphorylation)
        - Transfers a phosphate group to a molecule
      Phosphatase:
        - Removes a phosphate group from a substrate (dephosphorylation)
        - Catalyzes phosphate removal from a molecule
      Protease:
        - Breaks peptide bonds in proteins
        - Hydrolyzes peptide bonds
      Ligase:
        - Joins two molecules by forming a new bond (often using ATP)
        - Catalyzes bond formation to link molecules
      Isomerase:
        - Rearranges atoms within a molecule to form an isomer
        - Converts a molecule into its isomer
    

    Each enzyme class key has two phrasing variants. The generator picks one wording per question, so students see different phrasings across attempts while always being assessed on the same concept.

    Complete working example

    Organelle function matching -- A full problem using PopUp dropdowns to match organelles with their primary functions.

    ## TITLE('Match organelles to functions')
    ## DESCRIPTION
    ## Match each organelle with its primary function using
    ## PopUp dropdown widgets.
    ## ENDDESCRIPTION
    ## KEYWORDS('organelles','matching','PopUp','cell biology')
    ## DBsubject('Cell Biology')
    ## DBchapter('Organelles')
    ## DBsection('Function')
    ## Date('2026-02-15')
    ## Author('Author name')
    ## Institution('Institution name')
    
    DOCUMENT();
    loadMacros(
    	"PGstandard.pl",
    	"PGML.pl",
    	"parserPopUp.pl",
    	"PGcourse.pl",
    );
    
    @functions = ('ATP production', 'Protein sorting',
    	'Intracellular digestion', 'Lipid synthesis');
    
    $popup1 = PopUp(['?', @functions], 'ATP production');
    $popup2 = PopUp(['?', @functions], 'Protein sorting');
    $popup3 = PopUp(['?', @functions], 'Intracellular digestion');
    $popup4 = PopUp(['?', @functions], 'Lipid synthesis');
    
    BEGIN_PGML
    Match each organelle with its primary function.
    
    1. Mitochondrion [_]{$popup1}
    
    2. Golgi apparatus [_]{$popup2}
    
    3. Lysosome [_]{$popup3}
    
    4. Smooth ER [_]{$popup4}
    END_PGML
    
    ENDDOCUMENT();
    

    Apply it today

    • Write wrapper <div> tags directly in PGML whenever possible (Pattern 1).
    • Use MODES(HTML => ...) only for wrapper HTML built inside eval blocks (Pattern 2).
    • Always use [$var]* (trailing asterisk) for HTML variables to prevent escaping.
    • Define @choices once and use it for both PopUp widgets and right-column labels.
    • Test with multiple problemSeed values to verify shuffle mapping works correctly.
    • Use 4-8 pairs for optimal cognitive load and assessment effectiveness.
    • For YAML-based banks, define 8-20 keys with 2-4 phrasing variants each.
    • Run quality checks for parallel grammar, similar value length, and no keyword cues.
    • For more on colored emphasis, see Text Coloring and Emphasis. For statement-based questions, see Randomized MC True and False Statements.

    This page titled 6.5: Randomized Matching Problems was last modified on Fri, 27 Feb 2026 15:36:39 GMT and is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Neil R. Voss.