ConTeXt: MetaPost graphic in overlay setups shifts between pagesHow to debug METAPOST inlined in ConTeXt? (Or...

How to type a section sign (§) into the Minecraft client

The Defining Moment

Are Boeing 737-800’s grounded?

How to make a pipeline wait for end-of-file or stop after an error?

Why does processed meat contain preservatives, while canned fish needs not?

Which big number is bigger?

Why does nature favour the Laplacian?

How to pronounce 'C++' in Spanish

Binary Numbers Magic Trick

Critique of timeline aesthetic

What is the relationship between spectral sequences and obstruction theory?

Is there any limitation with Arduino Nano serial communication distance?

With a Canadian student visa, can I spend a night at Vancouver before continuing to Toronto?

How can I practically buy stocks?

Apply MapThread to all but one variable

What does KSP mean?

Checks user level and limit the data before saving it to mongoDB

How could Tony Stark make this in Endgame?

How can I place the product on a social media post better?

Term for maladaptive animal behavior that will lead to their demise?

Examples of subgroups where it's nontrivial to show closure under multiplication?

What happened to Captain America in Endgame?

Packing rectangles: Does rotation ever help?

How can Republicans who favour free markets, consistently express anger when they don't like the outcome of that choice?



ConTeXt: MetaPost graphic in overlay setups shifts between pages


How to debug METAPOST inlined in ConTeXt? (Or “message” primitive and “loggingall;” in inlined METAPOST)Use fancy page numbering using Metapost graphicConTeXt+MetaPost: Non-conflicting random background and foreground coloursparametric overlay in contextHow include MetaPost from ConTeXt to LaTeX?Metapost error related with ConTeXtMetapost graphics not aligned in ConTeXt TABLEConTeXt and Metafun: Using environment variables inside overlayvertically center all slides in ConTeXt with minimal setupsConTeXt: What are alternatives and rendering setups?













0















Background



A line is being drawn using MetaPost on an overlay, which is used as the background for a framed layer. The layer is embedded within a setups so that a dot's position on the timeline is recalculated each time. The calculation is based on the value of the current section's title text.



Problem



The horizontal bars at the each end of the timeline shifts a slight amount. Compare:



Chapter 1



Chapter 2



When shown overlapped, the difference is apparent, albeit subtle:



Shifted Bars



Code



The minimal working example is reasonably straightforward. The bulk of the code is taken up by parsing the number from the section title within startuseMPgraphic.



definepapersize[BookPaperSize][
width=8in,
height=6in,
]

setuppapersize[BookPaperSize]

% Specify the width and height here because the inline figures need to
% maintain aspect ratio while setting a pleasing width.
startsetups[BookIllustrationSetups]
setlayerframed[BookIllustrationLayer][
frame=off,
x=zeropoint,
y=1.25in,
width=makeupwidth,
background=BookTimelineOverlay,
]{}
stopsetups

setupbackgrounds[page][
background=BookIllustrationLayer,
setups=BookIllustrationSetups
]

definelayer[BookIllustrationLayer][
width=paperwidth,
height=paperheight,
]

defineoverlay[BookTimelineOverlay][useMPgraphic{BookTimelineGraphic}]

startuseMPgraphic{BookTimelineGraphic}
% Define constants
numeric EVENT_BEGAN, TIME_OFFSET;
EVENT_BEGAN := 13799;
TIME_OFFSET := 1.25in;
PATH_THICKNESS := 2pt;

% The book timeline title macro contains a number representing when the
% event transpired and additional information.
string sectionTitle, sectionTitleDigits;
sectionTitle := "getspecificstructuretitle{3}";
sectionTitleDigits := "";

% Extract only digits and decimals from the book timeline title macro.
for i = 0 upto length( sectionTitle ):
string sectionChar;
sectionChar := substring( i, i + 1 ) of sectionTitle;

% A space indicates that the number has no more digits.
if sectionChar = " ":
break;
fi;

% Concatentate all the digits together.
if ((sectionChar >= "0") and (sectionChar <= "9")) or (sectionChar = "."):
sectionTitleDigits := sectionTitleDigits & sectionChar;
fi;
endfor;

% Convert the digits from a string to a numeric value.
numeric eventTime;
eventTime := 0;

for i = scantokens( sectionTitleDigits ):
eventTime := i;
endfor;

numeric eventX;
eventX := 1 - (eventTime / EVENT_BEGAN);

% Draw the line.
draw (TIME_OFFSET, .5*overlayheight) -- (overlaywidth, .5*overlayheight)
withpen pencircle scaled PATH_THICKNESS;

% Draw starting |.
draw (TIME_OFFSET, 0) -- (TIME_OFFSET, overlayheight)
withpen pencircle scaled PATH_THICKNESS;

% Draw ending |.
draw (overlaywidth, 0) -- (overlaywidth, overlayheight)
withpen pencircle scaled PATH_THICKNESS;

% Draw the timeline's dot relative to the event on the timeline.
filldraw fullcircle scaled 9
shifted(
TIME_OFFSET + eventX * (overlaywidth - TIME_OFFSET), .5*overlayheight
);
stopuseMPgraphic

starttext
chapter[title={Inflation Theory},reference={inflation-theory}]
section[title={13,799 ± 0.021},reference={section}]
input ward

chapter[title={First Stars},reference={first-stars}]
section[title={13,689 ± 70},reference={section-1}]
input ward
stoptext


Questions



I'm wondering:




  • Why does the timeline bar shift slightly?

  • How can the shifting be eliminated such that the timeline bars precisely overlap regardless of the timeline's dot's location?


Bonus question:




  • How can the code be simplified, especially parsing the title?









share





























    0















    Background



    A line is being drawn using MetaPost on an overlay, which is used as the background for a framed layer. The layer is embedded within a setups so that a dot's position on the timeline is recalculated each time. The calculation is based on the value of the current section's title text.



    Problem



    The horizontal bars at the each end of the timeline shifts a slight amount. Compare:



    Chapter 1



    Chapter 2



    When shown overlapped, the difference is apparent, albeit subtle:



    Shifted Bars



    Code



    The minimal working example is reasonably straightforward. The bulk of the code is taken up by parsing the number from the section title within startuseMPgraphic.



    definepapersize[BookPaperSize][
    width=8in,
    height=6in,
    ]

    setuppapersize[BookPaperSize]

    % Specify the width and height here because the inline figures need to
    % maintain aspect ratio while setting a pleasing width.
    startsetups[BookIllustrationSetups]
    setlayerframed[BookIllustrationLayer][
    frame=off,
    x=zeropoint,
    y=1.25in,
    width=makeupwidth,
    background=BookTimelineOverlay,
    ]{}
    stopsetups

    setupbackgrounds[page][
    background=BookIllustrationLayer,
    setups=BookIllustrationSetups
    ]

    definelayer[BookIllustrationLayer][
    width=paperwidth,
    height=paperheight,
    ]

    defineoverlay[BookTimelineOverlay][useMPgraphic{BookTimelineGraphic}]

    startuseMPgraphic{BookTimelineGraphic}
    % Define constants
    numeric EVENT_BEGAN, TIME_OFFSET;
    EVENT_BEGAN := 13799;
    TIME_OFFSET := 1.25in;
    PATH_THICKNESS := 2pt;

    % The book timeline title macro contains a number representing when the
    % event transpired and additional information.
    string sectionTitle, sectionTitleDigits;
    sectionTitle := "getspecificstructuretitle{3}";
    sectionTitleDigits := "";

    % Extract only digits and decimals from the book timeline title macro.
    for i = 0 upto length( sectionTitle ):
    string sectionChar;
    sectionChar := substring( i, i + 1 ) of sectionTitle;

    % A space indicates that the number has no more digits.
    if sectionChar = " ":
    break;
    fi;

    % Concatentate all the digits together.
    if ((sectionChar >= "0") and (sectionChar <= "9")) or (sectionChar = "."):
    sectionTitleDigits := sectionTitleDigits & sectionChar;
    fi;
    endfor;

    % Convert the digits from a string to a numeric value.
    numeric eventTime;
    eventTime := 0;

    for i = scantokens( sectionTitleDigits ):
    eventTime := i;
    endfor;

    numeric eventX;
    eventX := 1 - (eventTime / EVENT_BEGAN);

    % Draw the line.
    draw (TIME_OFFSET, .5*overlayheight) -- (overlaywidth, .5*overlayheight)
    withpen pencircle scaled PATH_THICKNESS;

    % Draw starting |.
    draw (TIME_OFFSET, 0) -- (TIME_OFFSET, overlayheight)
    withpen pencircle scaled PATH_THICKNESS;

    % Draw ending |.
    draw (overlaywidth, 0) -- (overlaywidth, overlayheight)
    withpen pencircle scaled PATH_THICKNESS;

    % Draw the timeline's dot relative to the event on the timeline.
    filldraw fullcircle scaled 9
    shifted(
    TIME_OFFSET + eventX * (overlaywidth - TIME_OFFSET), .5*overlayheight
    );
    stopuseMPgraphic

    starttext
    chapter[title={Inflation Theory},reference={inflation-theory}]
    section[title={13,799 ± 0.021},reference={section}]
    input ward

    chapter[title={First Stars},reference={first-stars}]
    section[title={13,689 ± 70},reference={section-1}]
    input ward
    stoptext


    Questions



    I'm wondering:




    • Why does the timeline bar shift slightly?

    • How can the shifting be eliminated such that the timeline bars precisely overlap regardless of the timeline's dot's location?


    Bonus question:




    • How can the code be simplified, especially parsing the title?









    share



























      0












      0








      0








      Background



      A line is being drawn using MetaPost on an overlay, which is used as the background for a framed layer. The layer is embedded within a setups so that a dot's position on the timeline is recalculated each time. The calculation is based on the value of the current section's title text.



      Problem



      The horizontal bars at the each end of the timeline shifts a slight amount. Compare:



      Chapter 1



      Chapter 2



      When shown overlapped, the difference is apparent, albeit subtle:



      Shifted Bars



      Code



      The minimal working example is reasonably straightforward. The bulk of the code is taken up by parsing the number from the section title within startuseMPgraphic.



      definepapersize[BookPaperSize][
      width=8in,
      height=6in,
      ]

      setuppapersize[BookPaperSize]

      % Specify the width and height here because the inline figures need to
      % maintain aspect ratio while setting a pleasing width.
      startsetups[BookIllustrationSetups]
      setlayerframed[BookIllustrationLayer][
      frame=off,
      x=zeropoint,
      y=1.25in,
      width=makeupwidth,
      background=BookTimelineOverlay,
      ]{}
      stopsetups

      setupbackgrounds[page][
      background=BookIllustrationLayer,
      setups=BookIllustrationSetups
      ]

      definelayer[BookIllustrationLayer][
      width=paperwidth,
      height=paperheight,
      ]

      defineoverlay[BookTimelineOverlay][useMPgraphic{BookTimelineGraphic}]

      startuseMPgraphic{BookTimelineGraphic}
      % Define constants
      numeric EVENT_BEGAN, TIME_OFFSET;
      EVENT_BEGAN := 13799;
      TIME_OFFSET := 1.25in;
      PATH_THICKNESS := 2pt;

      % The book timeline title macro contains a number representing when the
      % event transpired and additional information.
      string sectionTitle, sectionTitleDigits;
      sectionTitle := "getspecificstructuretitle{3}";
      sectionTitleDigits := "";

      % Extract only digits and decimals from the book timeline title macro.
      for i = 0 upto length( sectionTitle ):
      string sectionChar;
      sectionChar := substring( i, i + 1 ) of sectionTitle;

      % A space indicates that the number has no more digits.
      if sectionChar = " ":
      break;
      fi;

      % Concatentate all the digits together.
      if ((sectionChar >= "0") and (sectionChar <= "9")) or (sectionChar = "."):
      sectionTitleDigits := sectionTitleDigits & sectionChar;
      fi;
      endfor;

      % Convert the digits from a string to a numeric value.
      numeric eventTime;
      eventTime := 0;

      for i = scantokens( sectionTitleDigits ):
      eventTime := i;
      endfor;

      numeric eventX;
      eventX := 1 - (eventTime / EVENT_BEGAN);

      % Draw the line.
      draw (TIME_OFFSET, .5*overlayheight) -- (overlaywidth, .5*overlayheight)
      withpen pencircle scaled PATH_THICKNESS;

      % Draw starting |.
      draw (TIME_OFFSET, 0) -- (TIME_OFFSET, overlayheight)
      withpen pencircle scaled PATH_THICKNESS;

      % Draw ending |.
      draw (overlaywidth, 0) -- (overlaywidth, overlayheight)
      withpen pencircle scaled PATH_THICKNESS;

      % Draw the timeline's dot relative to the event on the timeline.
      filldraw fullcircle scaled 9
      shifted(
      TIME_OFFSET + eventX * (overlaywidth - TIME_OFFSET), .5*overlayheight
      );
      stopuseMPgraphic

      starttext
      chapter[title={Inflation Theory},reference={inflation-theory}]
      section[title={13,799 ± 0.021},reference={section}]
      input ward

      chapter[title={First Stars},reference={first-stars}]
      section[title={13,689 ± 70},reference={section-1}]
      input ward
      stoptext


      Questions



      I'm wondering:




      • Why does the timeline bar shift slightly?

      • How can the shifting be eliminated such that the timeline bars precisely overlap regardless of the timeline's dot's location?


      Bonus question:




      • How can the code be simplified, especially parsing the title?









      share
















      Background



      A line is being drawn using MetaPost on an overlay, which is used as the background for a framed layer. The layer is embedded within a setups so that a dot's position on the timeline is recalculated each time. The calculation is based on the value of the current section's title text.



      Problem



      The horizontal bars at the each end of the timeline shifts a slight amount. Compare:



      Chapter 1



      Chapter 2



      When shown overlapped, the difference is apparent, albeit subtle:



      Shifted Bars



      Code



      The minimal working example is reasonably straightforward. The bulk of the code is taken up by parsing the number from the section title within startuseMPgraphic.



      definepapersize[BookPaperSize][
      width=8in,
      height=6in,
      ]

      setuppapersize[BookPaperSize]

      % Specify the width and height here because the inline figures need to
      % maintain aspect ratio while setting a pleasing width.
      startsetups[BookIllustrationSetups]
      setlayerframed[BookIllustrationLayer][
      frame=off,
      x=zeropoint,
      y=1.25in,
      width=makeupwidth,
      background=BookTimelineOverlay,
      ]{}
      stopsetups

      setupbackgrounds[page][
      background=BookIllustrationLayer,
      setups=BookIllustrationSetups
      ]

      definelayer[BookIllustrationLayer][
      width=paperwidth,
      height=paperheight,
      ]

      defineoverlay[BookTimelineOverlay][useMPgraphic{BookTimelineGraphic}]

      startuseMPgraphic{BookTimelineGraphic}
      % Define constants
      numeric EVENT_BEGAN, TIME_OFFSET;
      EVENT_BEGAN := 13799;
      TIME_OFFSET := 1.25in;
      PATH_THICKNESS := 2pt;

      % The book timeline title macro contains a number representing when the
      % event transpired and additional information.
      string sectionTitle, sectionTitleDigits;
      sectionTitle := "getspecificstructuretitle{3}";
      sectionTitleDigits := "";

      % Extract only digits and decimals from the book timeline title macro.
      for i = 0 upto length( sectionTitle ):
      string sectionChar;
      sectionChar := substring( i, i + 1 ) of sectionTitle;

      % A space indicates that the number has no more digits.
      if sectionChar = " ":
      break;
      fi;

      % Concatentate all the digits together.
      if ((sectionChar >= "0") and (sectionChar <= "9")) or (sectionChar = "."):
      sectionTitleDigits := sectionTitleDigits & sectionChar;
      fi;
      endfor;

      % Convert the digits from a string to a numeric value.
      numeric eventTime;
      eventTime := 0;

      for i = scantokens( sectionTitleDigits ):
      eventTime := i;
      endfor;

      numeric eventX;
      eventX := 1 - (eventTime / EVENT_BEGAN);

      % Draw the line.
      draw (TIME_OFFSET, .5*overlayheight) -- (overlaywidth, .5*overlayheight)
      withpen pencircle scaled PATH_THICKNESS;

      % Draw starting |.
      draw (TIME_OFFSET, 0) -- (TIME_OFFSET, overlayheight)
      withpen pencircle scaled PATH_THICKNESS;

      % Draw ending |.
      draw (overlaywidth, 0) -- (overlaywidth, overlayheight)
      withpen pencircle scaled PATH_THICKNESS;

      % Draw the timeline's dot relative to the event on the timeline.
      filldraw fullcircle scaled 9
      shifted(
      TIME_OFFSET + eventX * (overlaywidth - TIME_OFFSET), .5*overlayheight
      );
      stopuseMPgraphic

      starttext
      chapter[title={Inflation Theory},reference={inflation-theory}]
      section[title={13,799 ± 0.021},reference={section}]
      input ward

      chapter[title={First Stars},reference={first-stars}]
      section[title={13,689 ± 70},reference={section-1}]
      input ward
      stoptext


      Questions



      I'm wondering:




      • Why does the timeline bar shift slightly?

      • How can the shifting be eliminated such that the timeline bars precisely overlap regardless of the timeline's dot's location?


      Bonus question:




      • How can the code be simplified, especially parsing the title?







      context framed calculations metapost





      share














      share












      share



      share








      edited just now







      Dave Jarvis

















      asked 6 mins ago









      Dave JarvisDave Jarvis

      4,75684084




      4,75684084






















          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%2f488034%2fcontext-metapost-graphic-in-overlay-setups-shifts-between-pages%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%2f488034%2fcontext-metapost-graphic-in-overlay-setups-shifts-between-pages%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

          El tren de la libertad Índice Antecedentes "Porque yo decido" Desarrollo de la...

          Puerta de Hutt Referencias Enlaces externos Menú de navegación15°58′00″S 5°42′00″O /...

          Castillo d'Acher Características Menú de navegación