Define variables in document so that macro definition goes into preamble Announcing the...

Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?

What's the difference between the capability remove_users and delete_users?

Do wooden building fires get hotter than 600°C?

Semigroups with no morphisms between them

Are sorcerers unable to use the Careful Spell metamagic option on themselves?

How can I prevent/balance waiting and turtling as a response to cooldown mechanics

If the probability of a dog barking one or more times in a given hour is 84%, then what is the probability of a dog barking in 30 minutes?

Why do early math courses focus on the cross sections of a cone and not on other 3D objects?

Did Mueller's report provide an evidentiary basis for the claim of Russian govt election interference via social media?

Would it be easier to apply for a UK visa if there is a host family to sponsor for you in going there?

How to compare two different files line by line in unix?

Trademark violation for app?

Drawing spherical mirrors

Converted a Scalar function to a TVF function for parallel execution-Still running in Serial mode

Girl Hackers - Logic Puzzle

The test team as an enemy of development? And how can this be avoided?

Most bit efficient text communication method?

Prove that BD bisects angle ABC

How much damage would a cupful of neutron star matter do to the Earth?

Lagrange four-squares theorem --- deterministic complexity

Why weren't discrete x86 CPUs ever used in game hardware?

What makes a man succeed?

How many morphisms from 1 to 1+1 can there be?

How to save space when writing equations with cases?



Define variables in document so that macro definition goes into preamble



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Dividing preamble into smaller filessettowidth in preamble wrong with fontspec+lualatex w/ MWEDefine a macro expanding into quotesCustom variables defined in preambleDefine items with a custom name in preamble, use them in the documentShould urlstyle go into preamble or document body?Passing additional variables into macroVariable argument macro to define splitting polynomialDefine command that can only be used in the preambleError during expanding macro command in preamble












0















I've written some macros to add OMR characters to the generated document. The OMR characters are needed for an envelope inserter machine.



When I want to print OMR characters for a double-sided document, I have to put:



 DoubleSidedPrinting
AddOMR


I want to put my macro in a preamble that will be precompiled and be reused for several documents. In that case, I will only have to set DoubleSidedPrinting and AddOMR in each document. But this doesn't work. Do you know a workaround?



% The goal is to put this code in a reusable preamble
documentclass[12pt,twoside,a4paper]{article}

usepackage{eso-pic}
usepackage{rotating}
usepackage{graphicx}
usepackage{scrextend}
usepackage{lastpage}
usepackage{refcount}

newififAddOMR
defAddOMR{AddOMRtrue}
defOmitOMR{AddOMRfalse}

newififDoubleSidedPrinting
defSingleSidedPrinting{DoubleSidedPrintingfalse}
defDoubleSidedPrinting{DoubleSidedPrintingtrue}

%SingleSidedPrinting %%if I define SingleSidedPrinting (or DoubleSidedPrinting) on this line
DoubleSidedPrinting %%the code is working
AddOMR %%if I define SingleSidedPrinting (or DoubleSidedPrinting) on this line
%OmitOMR %%the code is working

makeatletter
newcommand*{LastOddCheck}{
ifoddvalue{page}
if@filesw
immediatewrite@auxout{
gdefstringLastOddPage{thevalue{page}}
}
fi
fi
}
newcommand*{LastOddPage}{0}

ifAddOMR
ClearShipoutPicture
AddToShipoutPicture{
ifDoubleSidedPrinting
ifoddc@page
LastOddCheck
ifnumLastOddPage=value{page}
put(11,503){linethickness{0.5mm}{line(1,0){17}}}
put(11,489.5){linethickness{0.5mm}{line(1,0){17}}}
put(11,475){linethickness{0.5mm}{line(1,0){17}}}
else
put(11,503){linethickness{0.5mm}{line(1,0){17}}}
put(11,475){linethickness{0.5mm}{line(1,0){17}}}
fi
else
fi
else
ifnumgetpagerefnumber{LastPage}=value{page}
put(11,503){linethickness{0.5mm}{line(1,0){17}}}
put(11,489.5){linethickness{0.5mm}{line(1,0){17}}}
put(11,475){linethickness{0.5mm}{line(1,0){17}}}
else
put(11,503){linethickness{0.5mm}{line(1,0){17}}}
put(11,475){linethickness{0.5mm}{line(1,0){17}}}
fi
fi
}
makeatother
else
fi

ifDoubleSidedPrinting
AtEndDocument{cleardoublepage}
else
fi

% This will be the end of the reusable preamble

%SingleSidedPrinting %%I would like to define SingleSidedPrinting (or DoubleSidedPrinting) only at this moment
%DoubleSidedPrinting %%but if I do so, the code is not working. Is there a workaround?

begin{document}

newpage %% page 1
mbox{Text on page 1}

newpage %% page 2
mbox{Text on page 2}

newpage %% page 3
mbox{Text on page 3}

newpage %% page 4
mbox{Text on page 4}

%newpage %% page 5
%mbox{Text on page 5}

end{document}









share|improve this question



























    0















    I've written some macros to add OMR characters to the generated document. The OMR characters are needed for an envelope inserter machine.



    When I want to print OMR characters for a double-sided document, I have to put:



     DoubleSidedPrinting
    AddOMR


    I want to put my macro in a preamble that will be precompiled and be reused for several documents. In that case, I will only have to set DoubleSidedPrinting and AddOMR in each document. But this doesn't work. Do you know a workaround?



    % The goal is to put this code in a reusable preamble
    documentclass[12pt,twoside,a4paper]{article}

    usepackage{eso-pic}
    usepackage{rotating}
    usepackage{graphicx}
    usepackage{scrextend}
    usepackage{lastpage}
    usepackage{refcount}

    newififAddOMR
    defAddOMR{AddOMRtrue}
    defOmitOMR{AddOMRfalse}

    newififDoubleSidedPrinting
    defSingleSidedPrinting{DoubleSidedPrintingfalse}
    defDoubleSidedPrinting{DoubleSidedPrintingtrue}

    %SingleSidedPrinting %%if I define SingleSidedPrinting (or DoubleSidedPrinting) on this line
    DoubleSidedPrinting %%the code is working
    AddOMR %%if I define SingleSidedPrinting (or DoubleSidedPrinting) on this line
    %OmitOMR %%the code is working

    makeatletter
    newcommand*{LastOddCheck}{
    ifoddvalue{page}
    if@filesw
    immediatewrite@auxout{
    gdefstringLastOddPage{thevalue{page}}
    }
    fi
    fi
    }
    newcommand*{LastOddPage}{0}

    ifAddOMR
    ClearShipoutPicture
    AddToShipoutPicture{
    ifDoubleSidedPrinting
    ifoddc@page
    LastOddCheck
    ifnumLastOddPage=value{page}
    put(11,503){linethickness{0.5mm}{line(1,0){17}}}
    put(11,489.5){linethickness{0.5mm}{line(1,0){17}}}
    put(11,475){linethickness{0.5mm}{line(1,0){17}}}
    else
    put(11,503){linethickness{0.5mm}{line(1,0){17}}}
    put(11,475){linethickness{0.5mm}{line(1,0){17}}}
    fi
    else
    fi
    else
    ifnumgetpagerefnumber{LastPage}=value{page}
    put(11,503){linethickness{0.5mm}{line(1,0){17}}}
    put(11,489.5){linethickness{0.5mm}{line(1,0){17}}}
    put(11,475){linethickness{0.5mm}{line(1,0){17}}}
    else
    put(11,503){linethickness{0.5mm}{line(1,0){17}}}
    put(11,475){linethickness{0.5mm}{line(1,0){17}}}
    fi
    fi
    }
    makeatother
    else
    fi

    ifDoubleSidedPrinting
    AtEndDocument{cleardoublepage}
    else
    fi

    % This will be the end of the reusable preamble

    %SingleSidedPrinting %%I would like to define SingleSidedPrinting (or DoubleSidedPrinting) only at this moment
    %DoubleSidedPrinting %%but if I do so, the code is not working. Is there a workaround?

    begin{document}

    newpage %% page 1
    mbox{Text on page 1}

    newpage %% page 2
    mbox{Text on page 2}

    newpage %% page 3
    mbox{Text on page 3}

    newpage %% page 4
    mbox{Text on page 4}

    %newpage %% page 5
    %mbox{Text on page 5}

    end{document}









    share|improve this question

























      0












      0








      0








      I've written some macros to add OMR characters to the generated document. The OMR characters are needed for an envelope inserter machine.



      When I want to print OMR characters for a double-sided document, I have to put:



       DoubleSidedPrinting
      AddOMR


      I want to put my macro in a preamble that will be precompiled and be reused for several documents. In that case, I will only have to set DoubleSidedPrinting and AddOMR in each document. But this doesn't work. Do you know a workaround?



      % The goal is to put this code in a reusable preamble
      documentclass[12pt,twoside,a4paper]{article}

      usepackage{eso-pic}
      usepackage{rotating}
      usepackage{graphicx}
      usepackage{scrextend}
      usepackage{lastpage}
      usepackage{refcount}

      newififAddOMR
      defAddOMR{AddOMRtrue}
      defOmitOMR{AddOMRfalse}

      newififDoubleSidedPrinting
      defSingleSidedPrinting{DoubleSidedPrintingfalse}
      defDoubleSidedPrinting{DoubleSidedPrintingtrue}

      %SingleSidedPrinting %%if I define SingleSidedPrinting (or DoubleSidedPrinting) on this line
      DoubleSidedPrinting %%the code is working
      AddOMR %%if I define SingleSidedPrinting (or DoubleSidedPrinting) on this line
      %OmitOMR %%the code is working

      makeatletter
      newcommand*{LastOddCheck}{
      ifoddvalue{page}
      if@filesw
      immediatewrite@auxout{
      gdefstringLastOddPage{thevalue{page}}
      }
      fi
      fi
      }
      newcommand*{LastOddPage}{0}

      ifAddOMR
      ClearShipoutPicture
      AddToShipoutPicture{
      ifDoubleSidedPrinting
      ifoddc@page
      LastOddCheck
      ifnumLastOddPage=value{page}
      put(11,503){linethickness{0.5mm}{line(1,0){17}}}
      put(11,489.5){linethickness{0.5mm}{line(1,0){17}}}
      put(11,475){linethickness{0.5mm}{line(1,0){17}}}
      else
      put(11,503){linethickness{0.5mm}{line(1,0){17}}}
      put(11,475){linethickness{0.5mm}{line(1,0){17}}}
      fi
      else
      fi
      else
      ifnumgetpagerefnumber{LastPage}=value{page}
      put(11,503){linethickness{0.5mm}{line(1,0){17}}}
      put(11,489.5){linethickness{0.5mm}{line(1,0){17}}}
      put(11,475){linethickness{0.5mm}{line(1,0){17}}}
      else
      put(11,503){linethickness{0.5mm}{line(1,0){17}}}
      put(11,475){linethickness{0.5mm}{line(1,0){17}}}
      fi
      fi
      }
      makeatother
      else
      fi

      ifDoubleSidedPrinting
      AtEndDocument{cleardoublepage}
      else
      fi

      % This will be the end of the reusable preamble

      %SingleSidedPrinting %%I would like to define SingleSidedPrinting (or DoubleSidedPrinting) only at this moment
      %DoubleSidedPrinting %%but if I do so, the code is not working. Is there a workaround?

      begin{document}

      newpage %% page 1
      mbox{Text on page 1}

      newpage %% page 2
      mbox{Text on page 2}

      newpage %% page 3
      mbox{Text on page 3}

      newpage %% page 4
      mbox{Text on page 4}

      %newpage %% page 5
      %mbox{Text on page 5}

      end{document}









      share|improve this question














      I've written some macros to add OMR characters to the generated document. The OMR characters are needed for an envelope inserter machine.



      When I want to print OMR characters for a double-sided document, I have to put:



       DoubleSidedPrinting
      AddOMR


      I want to put my macro in a preamble that will be precompiled and be reused for several documents. In that case, I will only have to set DoubleSidedPrinting and AddOMR in each document. But this doesn't work. Do you know a workaround?



      % The goal is to put this code in a reusable preamble
      documentclass[12pt,twoside,a4paper]{article}

      usepackage{eso-pic}
      usepackage{rotating}
      usepackage{graphicx}
      usepackage{scrextend}
      usepackage{lastpage}
      usepackage{refcount}

      newififAddOMR
      defAddOMR{AddOMRtrue}
      defOmitOMR{AddOMRfalse}

      newififDoubleSidedPrinting
      defSingleSidedPrinting{DoubleSidedPrintingfalse}
      defDoubleSidedPrinting{DoubleSidedPrintingtrue}

      %SingleSidedPrinting %%if I define SingleSidedPrinting (or DoubleSidedPrinting) on this line
      DoubleSidedPrinting %%the code is working
      AddOMR %%if I define SingleSidedPrinting (or DoubleSidedPrinting) on this line
      %OmitOMR %%the code is working

      makeatletter
      newcommand*{LastOddCheck}{
      ifoddvalue{page}
      if@filesw
      immediatewrite@auxout{
      gdefstringLastOddPage{thevalue{page}}
      }
      fi
      fi
      }
      newcommand*{LastOddPage}{0}

      ifAddOMR
      ClearShipoutPicture
      AddToShipoutPicture{
      ifDoubleSidedPrinting
      ifoddc@page
      LastOddCheck
      ifnumLastOddPage=value{page}
      put(11,503){linethickness{0.5mm}{line(1,0){17}}}
      put(11,489.5){linethickness{0.5mm}{line(1,0){17}}}
      put(11,475){linethickness{0.5mm}{line(1,0){17}}}
      else
      put(11,503){linethickness{0.5mm}{line(1,0){17}}}
      put(11,475){linethickness{0.5mm}{line(1,0){17}}}
      fi
      else
      fi
      else
      ifnumgetpagerefnumber{LastPage}=value{page}
      put(11,503){linethickness{0.5mm}{line(1,0){17}}}
      put(11,489.5){linethickness{0.5mm}{line(1,0){17}}}
      put(11,475){linethickness{0.5mm}{line(1,0){17}}}
      else
      put(11,503){linethickness{0.5mm}{line(1,0){17}}}
      put(11,475){linethickness{0.5mm}{line(1,0){17}}}
      fi
      fi
      }
      makeatother
      else
      fi

      ifDoubleSidedPrinting
      AtEndDocument{cleardoublepage}
      else
      fi

      % This will be the end of the reusable preamble

      %SingleSidedPrinting %%I would like to define SingleSidedPrinting (or DoubleSidedPrinting) only at this moment
      %DoubleSidedPrinting %%but if I do so, the code is not working. Is there a workaround?

      begin{document}

      newpage %% page 1
      mbox{Text on page 1}

      newpage %% page 2
      mbox{Text on page 2}

      newpage %% page 3
      mbox{Text on page 3}

      newpage %% page 4
      mbox{Text on page 4}

      %newpage %% page 5
      %mbox{Text on page 5}

      end{document}






      macros preamble variable






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 12 mins ago









      user3048741user3048741

      756




      756






















          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%2f485706%2fdefine-variables-in-document-so-that-macro-definition-goes-into-preamble%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%2f485706%2fdefine-variables-in-document-so-that-macro-definition-goes-into-preamble%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

          Paper upload error, “Upload failed: The top margin is 0.715 in on page 3, which is below the required...

          Emraan Hashmi Filmografia | Linki zewnętrzne | Menu nawigacyjneGulshan GroverGulshan...

          How can I write this formula?newline and italics added with leqWhy does widehat behave differently if I...