Use ifthenelse{equal{ on a number called from referenceMacro with an array and a customisable number of columns (from 2 to 5)“Missing number” error using `pgfmathsetmacro` with the `ifthenelse` operatorconvert outcome of reference to regular numberUse result from pgfmath with xifthenHow to use values from a 2d array in a tikz picture ? (out of bounds error)Swap two array elementsifthenelse + equal behaves weirdlyunderstanding “ifthenelse” command with pgf random numberHow test value of a command with `ifthenelse` and `equal`?ifthenelse as an argument to equal

What major Native American tribes were around Santa Fe during the late 1850s?

Can we have a perfect cadence in a minor key?

Why does Async/Await work properly when the loop is inside the async function and not the other way around?

Is it improper etiquette to ask your opponent what his/her rating is before the game?

Bob has never been a M before

Gibbs free energy in standard state vs. equilibrium

Database accidentally deleted with a bash script

Extending the spectral theorem for bounded self adjoint operators to bounded normal operators

How does the reference system of the Majjhima Nikaya work?

Visiting the UK as unmarried couple

What is the difference between "Do you interest" and "...interested in" something?

Should I stop contributing to retirement accounts?

Flux received by a negative charge

Is XSS in canonical link possible?

Reply 'no position' while the job posting is still there

Could the E-bike drivetrain wear down till needing replacement after 400 km?

Longest common substring in linear time

Can I sign legal documents with a smiley face?

What (else) happened July 1st 1858 in London?

Journal losing indexing services

What's the difference between 違法 and 不法?

Will adding a BY-SA image to a blog post make the entire post BY-SA?

Do the concepts of IP address and network interface not belong to the same layer?

Is it possible to have a strip of cold climate in the middle of a planet?



Use ifthenelseequal on a number called from reference


Macro with an array and a customisable number of columns (from 2 to 5)“Missing number” error using `pgfmathsetmacro` with the `ifthenelse` operatorconvert outcome of reference to regular numberUse result from pgfmath with xifthenHow to use values from a 2d array in a tikz picture ? (out of bounds error)Swap two array elementsifthenelse + equal behaves weirdlyunderstanding “ifthenelse” command with pgf random numberHow test value of a command with `ifthenelse` and `equal`?ifthenelse as an argument to equal













2















I want to store an answer key for an exam and then automatically move the multiple choice answer choices around for each question match its predetermined answer. (I need to conform my multiple choice exam to a predetermined answer key in order to use these cool scratch-off scantrons called "IF-AT" scantrons).



I have a partial solution (see MWE at bottom) based one three steps.



  1. Store the answers for the exam in an array using arrayjob.sty, 1234 meaning ABCD respectively. For example, usepackagearrayjob newarrayanswerkey readarrayanswerkey3&4 records the answer to Q1 as C and the answer to Q2 as D.

  2. Then arabicquestion gives you the question number, and so answerkey(arabicquestion) gives you that previously stored answer for that question number.

  3. Use ifthenelse to execute different behavior based on that number answerkey(arabicquestion).

However, I can't figure out how to get ifthenelse to read answerkey(arabicquestion). In other words,



ifthenelseequal1answerkey(arabicquestion)some code


doesn't work.
I think it's a matter of expanding macros at the right time.



In the MWE below I commented out the code testing arrayjob.sty + ifthen.sty because it fails to compile.



For good measure, I also tried replacing the two packages with pgfmath.sty and fp.sty respectively (Qs 6, 7, 8 in MWE below), but no combination compiles.



documentclassexam
usepackageifthen, fp, arrayjob, pgfmath
newarrayanswerkey %arrayjob
readarrayanswerkey4&3&2&1&1&1&1&1
defanswerkeytwo,4,3,2,1,1,1,1,1 %pgfmath
begindocument
beginquestions
question testing arrayjob...
answerkey(arabicquestion)
question testing pgf...
pgfmathparseanswerkeytwo[arabicquestion]pgfmathresult
question testing ifthen...
ifthenelseequal 2 2itbetrueitbefalse.
question testing fp...
FPifeq 1 1 itbetrueelse itbefalsefi.
question testing arrayjob + ifthen... (should print itbetrue)
%ifthenelseequal 1
% answerkey(arabicquestion)
% itbetrueitbefalse.
question testing arrayjob + fp... (should print itbetrue)
%FPifeq 1
% answerkeyone(arabicquestion)
% itbetrue else itbefalse fi.
question testing pgfmath + ifthen... (should print itbetrue)
%ifthenelseequal 1
% pgfmathparseanswerkeytwo[arabicquestion]pgfmathresult
% itbetrueitbefalse.
question testing pgfmath + fp... (should print itbetrue)
%FPifeq 1
% pgfmathparseanswerkeytwo[arabicquestion]pgfmathresult
% itbetrueelse itbefalsefi.
endquestions
enddocument


enter image description here



So how do I get answerkey(arabicquestion) to expand early enough for ifthenelseequal1answerkey(arabicquestion) to work?










share|improve this question


























    2















    I want to store an answer key for an exam and then automatically move the multiple choice answer choices around for each question match its predetermined answer. (I need to conform my multiple choice exam to a predetermined answer key in order to use these cool scratch-off scantrons called "IF-AT" scantrons).



    I have a partial solution (see MWE at bottom) based one three steps.



    1. Store the answers for the exam in an array using arrayjob.sty, 1234 meaning ABCD respectively. For example, usepackagearrayjob newarrayanswerkey readarrayanswerkey3&4 records the answer to Q1 as C and the answer to Q2 as D.

    2. Then arabicquestion gives you the question number, and so answerkey(arabicquestion) gives you that previously stored answer for that question number.

    3. Use ifthenelse to execute different behavior based on that number answerkey(arabicquestion).

    However, I can't figure out how to get ifthenelse to read answerkey(arabicquestion). In other words,



    ifthenelseequal1answerkey(arabicquestion)some code


    doesn't work.
    I think it's a matter of expanding macros at the right time.



    In the MWE below I commented out the code testing arrayjob.sty + ifthen.sty because it fails to compile.



    For good measure, I also tried replacing the two packages with pgfmath.sty and fp.sty respectively (Qs 6, 7, 8 in MWE below), but no combination compiles.



    documentclassexam
    usepackageifthen, fp, arrayjob, pgfmath
    newarrayanswerkey %arrayjob
    readarrayanswerkey4&3&2&1&1&1&1&1
    defanswerkeytwo,4,3,2,1,1,1,1,1 %pgfmath
    begindocument
    beginquestions
    question testing arrayjob...
    answerkey(arabicquestion)
    question testing pgf...
    pgfmathparseanswerkeytwo[arabicquestion]pgfmathresult
    question testing ifthen...
    ifthenelseequal 2 2itbetrueitbefalse.
    question testing fp...
    FPifeq 1 1 itbetrueelse itbefalsefi.
    question testing arrayjob + ifthen... (should print itbetrue)
    %ifthenelseequal 1
    % answerkey(arabicquestion)
    % itbetrueitbefalse.
    question testing arrayjob + fp... (should print itbetrue)
    %FPifeq 1
    % answerkeyone(arabicquestion)
    % itbetrue else itbefalse fi.
    question testing pgfmath + ifthen... (should print itbetrue)
    %ifthenelseequal 1
    % pgfmathparseanswerkeytwo[arabicquestion]pgfmathresult
    % itbetrueitbefalse.
    question testing pgfmath + fp... (should print itbetrue)
    %FPifeq 1
    % pgfmathparseanswerkeytwo[arabicquestion]pgfmathresult
    % itbetrueelse itbefalsefi.
    endquestions
    enddocument


    enter image description here



    So how do I get answerkey(arabicquestion)} to expand early enough for ifthenelseequal1answerkey(arabicquestion)} to work?










    share|improve this question
























      2












      2








      2








      I want to store an answer key for an exam and then automatically move the multiple choice answer choices around for each question match its predetermined answer. (I need to conform my multiple choice exam to a predetermined answer key in order to use these cool scratch-off scantrons called "IF-AT" scantrons).



      I have a partial solution (see MWE at bottom) based one three steps.



      1. Store the answers for the exam in an array using arrayjob.sty, 1234 meaning ABCD respectively. For example, usepackagearrayjob newarrayanswerkey readarrayanswerkey3&4 records the answer to Q1 as C and the answer to Q2 as D.

      2. Then arabicquestion gives you the question number, and so answerkey(arabicquestion) gives you that previously stored answer for that question number.

      3. Use ifthenelse to execute different behavior based on that number answerkey(arabicquestion).

      However, I can't figure out how to get ifthenelse to read answerkey(arabicquestion). In other words,



      ifthenelseequal1answerkey(arabicquestion)some code


      doesn't work.
      I think it's a matter of expanding macros at the right time.



      In the MWE below I commented out the code testing arrayjob.sty + ifthen.sty because it fails to compile.



      For good measure, I also tried replacing the two packages with pgfmath.sty and fp.sty respectively (Qs 6, 7, 8 in MWE below), but no combination compiles.



      documentclassexam
      usepackageifthen, fp, arrayjob, pgfmath
      newarrayanswerkey %arrayjob
      readarrayanswerkey4&3&2&1&1&1&1&1
      defanswerkeytwo,4,3,2,1,1,1,1,1 %pgfmath
      begindocument
      beginquestions
      question testing arrayjob...
      answerkey(arabicquestion)
      question testing pgf...
      pgfmathparseanswerkeytwo[arabicquestion]pgfmathresult
      question testing ifthen...
      ifthenelseequal 2 2itbetrueitbefalse.
      question testing fp...
      FPifeq 1 1 itbetrueelse itbefalsefi.
      question testing arrayjob + ifthen... (should print itbetrue)
      %ifthenelseequal 1
      % answerkey(arabicquestion)
      % itbetrueitbefalse.
      question testing arrayjob + fp... (should print itbetrue)
      %FPifeq 1
      % answerkeyone(arabicquestion)
      % itbetrue else itbefalse fi.
      question testing pgfmath + ifthen... (should print itbetrue)
      %ifthenelseequal 1
      % pgfmathparseanswerkeytwo[arabicquestion]pgfmathresult
      % itbetrueitbefalse.
      question testing pgfmath + fp... (should print itbetrue)
      %FPifeq 1
      % pgfmathparseanswerkeytwo[arabicquestion]pgfmathresult
      % itbetrueelse itbefalsefi.
      endquestions
      enddocument


      enter image description here



      So how do I get answerkey(arabicquestion)} to expand early enough for ifthenelseequal1answerkey(arabicquestion)} to work?










      share|improve this question














      I want to store an answer key for an exam and then automatically move the multiple choice answer choices around for each question match its predetermined answer. (I need to conform my multiple choice exam to a predetermined answer key in order to use these cool scratch-off scantrons called "IF-AT" scantrons).



      I have a partial solution (see MWE at bottom) based one three steps.



      1. Store the answers for the exam in an array using arrayjob.sty, 1234 meaning ABCD respectively. For example, usepackagearrayjob newarrayanswerkey readarrayanswerkey3&4 records the answer to Q1 as C and the answer to Q2 as D.

      2. Then arabicquestion gives you the question number, and so answerkey(arabicquestion) gives you that previously stored answer for that question number.

      3. Use ifthenelse to execute different behavior based on that number answerkey(arabicquestion).

      However, I can't figure out how to get ifthenelse to read answerkey(arabicquestion). In other words,



      ifthenelseequal1answerkey(arabicquestion)some code


      doesn't work.
      I think it's a matter of expanding macros at the right time.



      In the MWE below I commented out the code testing arrayjob.sty + ifthen.sty because it fails to compile.



      For good measure, I also tried replacing the two packages with pgfmath.sty and fp.sty respectively (Qs 6, 7, 8 in MWE below), but no combination compiles.



      documentclassexam
      usepackageifthen, fp, arrayjob, pgfmath
      newarrayanswerkey %arrayjob
      readarrayanswerkey4&3&2&1&1&1&1&1
      defanswerkeytwo,4,3,2,1,1,1,1,1 %pgfmath
      begindocument
      beginquestions
      question testing arrayjob...
      answerkey(arabicquestion)
      question testing pgf...
      pgfmathparseanswerkeytwo[arabicquestion]pgfmathresult
      question testing ifthen...
      ifthenelseequal 2 2itbetrueitbefalse.
      question testing fp...
      FPifeq 1 1 itbetrueelse itbefalsefi.
      question testing arrayjob + ifthen... (should print itbetrue)
      %ifthenelseequal 1
      % answerkey(arabicquestion)
      % itbetrueitbefalse.
      question testing arrayjob + fp... (should print itbetrue)
      %FPifeq 1
      % answerkeyone(arabicquestion)
      % itbetrue else itbefalse fi.
      question testing pgfmath + ifthen... (should print itbetrue)
      %ifthenelseequal 1
      % pgfmathparseanswerkeytwo[arabicquestion]pgfmathresult
      % itbetrueitbefalse.
      question testing pgfmath + fp... (should print itbetrue)
      %FPifeq 1
      % pgfmathparseanswerkeytwo[arabicquestion]pgfmathresult
      % itbetrueelse itbefalsefi.
      endquestions
      enddocument


      enter image description here



      So how do I get answerkey(arabicquestion)} to expand early enough for ifthenelseequal1answerkey(arabicquestion)} to work?







      arrays pgfmath fp ifthenelse






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 10 mins ago









      Matt SMatt S

      505




      505




















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "85"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f481261%2fuse-ifthenelse-equal-on-a-number-called-from-reference%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f481261%2fuse-ifthenelse-equal-on-a-number-called-from-reference%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          acmart: Multiple authors: all with same affiliation, one author an additional affiliationHow to Write Names of Multiple Authors with Shared Affiliation in ACM 2017 Template?Multiple authors with different primary affiliation, but same additional affiliationSame affiliation for all authors without extra packagesIOS-Book-Article.cls: one author with multiple affiliationacmart: Shared Author AffiliationMultiple authors with different primary affiliation, but same additional affiliationAuthor affiliation with only 1 authorAdding Multiple Authors with Different Affiliation in LaTeX ArticleLaTeX: Multiple authors stays on same lineHow to Label Multiple Authors with Same DescriptionHow to make two authors use the same affiliationTwo authors with same affiliation on finished front page

          How to write “ä” and other umlauts and accented letters in bibliography?Accents in BibTeXSorting references with special characters alphabeticallyUse ae ligature in bibliographyEastern European nameInverted circumflex in BibTexBibTex, non-ascii initials and nameptr fproblems with accent in LatexHow to add a Ø to my bibliography from Jabref?References without accentsTroubles when trying to cite St“omer-Verlet in ”title" field of a bib entryComprehensive list of accented charactersHow to type the letter “i” with two dots (diaeresis) in math mode?Problem with glossary text and accented lettersSpecial character in bibliographyAccented letters, Unicode and LaTeX accentsHow to stop natbib from modifying bibliography styleCitation of a paper with non-standard characters by BibtexWrite accented characters to file using writeHow to group the bibliography alphabetically, if some surnames start with “accented” characters?How can I automatically capitalize significant words in my bibliography?

          How to force a table into page width?How to make table spanning textwidthMaking table width fit into text widthTable with tabular, column type p grabbing available spaceMaking widths of tables equal to width of textblocklatex tabular width the same as the textwidthMake tabular span textwidth exactlySet width of table to be the whole line or a given portion of itIs the tabu package obsolete?What is the difference between tabular, tabular* and tabularx environments?How can i set the width of a table?Making table width fit into text widthTabular and grid typesettingMake table use page widthTable exceeds page widthtable width automatically to page widthHow to shrink table to page widthForce table column to be zero widthTable width exceeds the page widthTable extending beyond the page widthforce longtable to text width