ConTeXt: MetaPost graphic in overlay setups shifts between pagesHow 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?
how to interpret this t result?
Single Colour Mastermind Problem
How can Republicans who favour free markets, consistently express anger when they don't like the outcome of that choice?
What does KSP mean?
Realistic Necromancy?
How to make a pipeline wait for end-of-file or stop after an error?
What is the relationship between spectral sequences and obstruction theory?
Is creating your own "experiment" considered cheating during a physics exam?
How to back up a running remote server?
Will this character get back his Infinity Stone?
Will a top journal at least read my introduction?
Pulling the rope with one hand is as heavy as with two hands?
Phrase for the opposite of "foolproof"
How can I practically buy stocks?
Why was the Spitfire's elliptical wing almost uncopied by other aircraft of World War 2?
How can the Zone of Truth spell be defeated without the caster knowing?
How could Tony Stark make this in Endgame?
Examples of non trivial equivalence relations , I mean equivalence relations without the expression " same ... as" in their definition?
Was there a shared-world project before "Thieves World"?
How much cash can I safely carry into the USA and avoid civil forfeiture?
How exactly does Hawking radiation decrease the mass of black holes?
Packing rectangles: Does rotation ever help?
How to stop co-workers from teasing me because I know Russian?
Error message with tabularx
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?
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:
When shown overlapped, the difference is apparent, albeit subtle:
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][useMPgraphicBookTimelineGraphic]
startuseMPgraphicBookTimelineGraphic
% Define constants
numeric EVENT_BEGAN, TIME_OFFSET, PATH_THICKNESS;
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 := "getspecificstructuretitle3";
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
add a comment |
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:
When shown overlapped, the difference is apparent, albeit subtle:
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][useMPgraphicBookTimelineGraphic]
startuseMPgraphicBookTimelineGraphic
% Define constants
numeric EVENT_BEGAN, TIME_OFFSET, PATH_THICKNESS;
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 := "getspecificstructuretitle3";
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
1
Why don't you draw the rule as part ofsetuphead
? Why do you try usefor line continuation? MetaPost scans until a semicolon and
is actually a TeX control sequence which expands to a blank space.
– Henri Menke
4 hours ago
add a comment |
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:
When shown overlapped, the difference is apparent, albeit subtle:
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][useMPgraphicBookTimelineGraphic]
startuseMPgraphicBookTimelineGraphic
% Define constants
numeric EVENT_BEGAN, TIME_OFFSET, PATH_THICKNESS;
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 := "getspecificstructuretitle3";
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
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:
When shown overlapped, the difference is apparent, albeit subtle:
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][useMPgraphicBookTimelineGraphic]
startuseMPgraphicBookTimelineGraphic
% Define constants
numeric EVENT_BEGAN, TIME_OFFSET, PATH_THICKNESS;
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 := "getspecificstructuretitle3";
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
context framed calculations metapost
edited 5 hours ago
Dave Jarvis
asked 5 hours ago
Dave JarvisDave Jarvis
4,77184084
4,77184084
1
Why don't you draw the rule as part ofsetuphead
? Why do you try usefor line continuation? MetaPost scans until a semicolon and
is actually a TeX control sequence which expands to a blank space.
– Henri Menke
4 hours ago
add a comment |
1
Why don't you draw the rule as part ofsetuphead
? Why do you try usefor line continuation? MetaPost scans until a semicolon and
is actually a TeX control sequence which expands to a blank space.
– Henri Menke
4 hours ago
1
1
Why don't you draw the rule as part of
setuphead
? Why do you try use
for line continuation? MetaPost scans until a semicolon and
is actually a TeX control sequence which expands to a blank space.– Henri Menke
4 hours ago
Why don't you draw the rule as part of
setuphead
? Why do you try use
for line continuation? MetaPost scans until a semicolon and
is actually a TeX control sequence which expands to a blank space.– Henri Menke
4 hours ago
add a comment |
1 Answer
1
active
oldest
votes
The placement of the dot modifies the bounding box. The most ad-hoc solution to this problem is
- Save the bounding box before drawing the dot
- Draw the dot
- Restore the bounding box without dot
The dot will then leak out of the bounding box but that is only a tiny bit.
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][useMPgraphicBookTimelineGraphic]
startuseMPgraphicBookTimelineGraphic
% Define constants
numeric EVENT_BEGAN, TIME_OFFSET, PATH_THICKNESS;
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 := "getspecificstructuretitle3";
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;
% The dot will change the size of bounding box, so we will just save the
% bounding box without the dot for later
path p ; p := bbox currentpicture ;
% 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
);
% Restore the bounding box without dot
setbounds currentpicture to p ;
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
Here is a little shorter version of your code, using Lua to parse the chapter title and using the MetaPost drawing as a background for the text layer of the page directly.
definepapersize
[BookPaperSize]
[width=8in,
height=6in]
setuppapersize[BookPaperSize]
defineoverlay
[BookTimelineOverlay]
[useMPgraphicBookTimelineGraphic]
setupbackgrounds
[text]
[background=BookTimelineOverlay]
startluacode
function userdata.parsetitle(title)
local a, b = string.match(title, "(%d+),(%d+)")
return table.concat( a, b , "")
end
stopluacode
startuseMPgraphicBookTimelineGraphic
% Define constants
numeric EVENT_BEGAN;
EVENT_BEGAN := 13799;
% Convert the digits from a string to a numeric value.
numeric eventX;
eventX := lua("mp.print(userdata.parsetitle('getspecificstructuretitle3'))") ;
eventX := 1 - (eventX / EVENT_BEGAN);
numeric wb, hb ; wb := 3.33in ; hb := .33in ;
pickup pencircle scaled 2pt;
picture p ; p := image(
% Draw the line.
draw (0, .5*hb) -- (wb, .5*hb) ;
% Draw starting |.
draw (0, 0) -- (0, hb) ;
% Draw ending |.
draw (wb, 0) -- (wb, hb) ;
% Draw the timeline's dot relative to the event on the timeline.
filldraw fullcircle scaled 9 shifted (eventX * wb, .5*hb);
);
numeric h ; h := OverlayHeight ;
draw p shifted (-.33in, h - hb - .33in);
setbounds currentpicture to OverlayBox ;
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The placement of the dot modifies the bounding box. The most ad-hoc solution to this problem is
- Save the bounding box before drawing the dot
- Draw the dot
- Restore the bounding box without dot
The dot will then leak out of the bounding box but that is only a tiny bit.
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][useMPgraphicBookTimelineGraphic]
startuseMPgraphicBookTimelineGraphic
% Define constants
numeric EVENT_BEGAN, TIME_OFFSET, PATH_THICKNESS;
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 := "getspecificstructuretitle3";
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;
% The dot will change the size of bounding box, so we will just save the
% bounding box without the dot for later
path p ; p := bbox currentpicture ;
% 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
);
% Restore the bounding box without dot
setbounds currentpicture to p ;
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
Here is a little shorter version of your code, using Lua to parse the chapter title and using the MetaPost drawing as a background for the text layer of the page directly.
definepapersize
[BookPaperSize]
[width=8in,
height=6in]
setuppapersize[BookPaperSize]
defineoverlay
[BookTimelineOverlay]
[useMPgraphicBookTimelineGraphic]
setupbackgrounds
[text]
[background=BookTimelineOverlay]
startluacode
function userdata.parsetitle(title)
local a, b = string.match(title, "(%d+),(%d+)")
return table.concat( a, b , "")
end
stopluacode
startuseMPgraphicBookTimelineGraphic
% Define constants
numeric EVENT_BEGAN;
EVENT_BEGAN := 13799;
% Convert the digits from a string to a numeric value.
numeric eventX;
eventX := lua("mp.print(userdata.parsetitle('getspecificstructuretitle3'))") ;
eventX := 1 - (eventX / EVENT_BEGAN);
numeric wb, hb ; wb := 3.33in ; hb := .33in ;
pickup pencircle scaled 2pt;
picture p ; p := image(
% Draw the line.
draw (0, .5*hb) -- (wb, .5*hb) ;
% Draw starting |.
draw (0, 0) -- (0, hb) ;
% Draw ending |.
draw (wb, 0) -- (wb, hb) ;
% Draw the timeline's dot relative to the event on the timeline.
filldraw fullcircle scaled 9 shifted (eventX * wb, .5*hb);
);
numeric h ; h := OverlayHeight ;
draw p shifted (-.33in, h - hb - .33in);
setbounds currentpicture to OverlayBox ;
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
add a comment |
The placement of the dot modifies the bounding box. The most ad-hoc solution to this problem is
- Save the bounding box before drawing the dot
- Draw the dot
- Restore the bounding box without dot
The dot will then leak out of the bounding box but that is only a tiny bit.
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][useMPgraphicBookTimelineGraphic]
startuseMPgraphicBookTimelineGraphic
% Define constants
numeric EVENT_BEGAN, TIME_OFFSET, PATH_THICKNESS;
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 := "getspecificstructuretitle3";
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;
% The dot will change the size of bounding box, so we will just save the
% bounding box without the dot for later
path p ; p := bbox currentpicture ;
% 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
);
% Restore the bounding box without dot
setbounds currentpicture to p ;
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
Here is a little shorter version of your code, using Lua to parse the chapter title and using the MetaPost drawing as a background for the text layer of the page directly.
definepapersize
[BookPaperSize]
[width=8in,
height=6in]
setuppapersize[BookPaperSize]
defineoverlay
[BookTimelineOverlay]
[useMPgraphicBookTimelineGraphic]
setupbackgrounds
[text]
[background=BookTimelineOverlay]
startluacode
function userdata.parsetitle(title)
local a, b = string.match(title, "(%d+),(%d+)")
return table.concat( a, b , "")
end
stopluacode
startuseMPgraphicBookTimelineGraphic
% Define constants
numeric EVENT_BEGAN;
EVENT_BEGAN := 13799;
% Convert the digits from a string to a numeric value.
numeric eventX;
eventX := lua("mp.print(userdata.parsetitle('getspecificstructuretitle3'))") ;
eventX := 1 - (eventX / EVENT_BEGAN);
numeric wb, hb ; wb := 3.33in ; hb := .33in ;
pickup pencircle scaled 2pt;
picture p ; p := image(
% Draw the line.
draw (0, .5*hb) -- (wb, .5*hb) ;
% Draw starting |.
draw (0, 0) -- (0, hb) ;
% Draw ending |.
draw (wb, 0) -- (wb, hb) ;
% Draw the timeline's dot relative to the event on the timeline.
filldraw fullcircle scaled 9 shifted (eventX * wb, .5*hb);
);
numeric h ; h := OverlayHeight ;
draw p shifted (-.33in, h - hb - .33in);
setbounds currentpicture to OverlayBox ;
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
add a comment |
The placement of the dot modifies the bounding box. The most ad-hoc solution to this problem is
- Save the bounding box before drawing the dot
- Draw the dot
- Restore the bounding box without dot
The dot will then leak out of the bounding box but that is only a tiny bit.
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][useMPgraphicBookTimelineGraphic]
startuseMPgraphicBookTimelineGraphic
% Define constants
numeric EVENT_BEGAN, TIME_OFFSET, PATH_THICKNESS;
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 := "getspecificstructuretitle3";
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;
% The dot will change the size of bounding box, so we will just save the
% bounding box without the dot for later
path p ; p := bbox currentpicture ;
% 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
);
% Restore the bounding box without dot
setbounds currentpicture to p ;
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
Here is a little shorter version of your code, using Lua to parse the chapter title and using the MetaPost drawing as a background for the text layer of the page directly.
definepapersize
[BookPaperSize]
[width=8in,
height=6in]
setuppapersize[BookPaperSize]
defineoverlay
[BookTimelineOverlay]
[useMPgraphicBookTimelineGraphic]
setupbackgrounds
[text]
[background=BookTimelineOverlay]
startluacode
function userdata.parsetitle(title)
local a, b = string.match(title, "(%d+),(%d+)")
return table.concat( a, b , "")
end
stopluacode
startuseMPgraphicBookTimelineGraphic
% Define constants
numeric EVENT_BEGAN;
EVENT_BEGAN := 13799;
% Convert the digits from a string to a numeric value.
numeric eventX;
eventX := lua("mp.print(userdata.parsetitle('getspecificstructuretitle3'))") ;
eventX := 1 - (eventX / EVENT_BEGAN);
numeric wb, hb ; wb := 3.33in ; hb := .33in ;
pickup pencircle scaled 2pt;
picture p ; p := image(
% Draw the line.
draw (0, .5*hb) -- (wb, .5*hb) ;
% Draw starting |.
draw (0, 0) -- (0, hb) ;
% Draw ending |.
draw (wb, 0) -- (wb, hb) ;
% Draw the timeline's dot relative to the event on the timeline.
filldraw fullcircle scaled 9 shifted (eventX * wb, .5*hb);
);
numeric h ; h := OverlayHeight ;
draw p shifted (-.33in, h - hb - .33in);
setbounds currentpicture to OverlayBox ;
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
The placement of the dot modifies the bounding box. The most ad-hoc solution to this problem is
- Save the bounding box before drawing the dot
- Draw the dot
- Restore the bounding box without dot
The dot will then leak out of the bounding box but that is only a tiny bit.
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][useMPgraphicBookTimelineGraphic]
startuseMPgraphicBookTimelineGraphic
% Define constants
numeric EVENT_BEGAN, TIME_OFFSET, PATH_THICKNESS;
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 := "getspecificstructuretitle3";
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;
% The dot will change the size of bounding box, so we will just save the
% bounding box without the dot for later
path p ; p := bbox currentpicture ;
% 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
);
% Restore the bounding box without dot
setbounds currentpicture to p ;
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
Here is a little shorter version of your code, using Lua to parse the chapter title and using the MetaPost drawing as a background for the text layer of the page directly.
definepapersize
[BookPaperSize]
[width=8in,
height=6in]
setuppapersize[BookPaperSize]
defineoverlay
[BookTimelineOverlay]
[useMPgraphicBookTimelineGraphic]
setupbackgrounds
[text]
[background=BookTimelineOverlay]
startluacode
function userdata.parsetitle(title)
local a, b = string.match(title, "(%d+),(%d+)")
return table.concat( a, b , "")
end
stopluacode
startuseMPgraphicBookTimelineGraphic
% Define constants
numeric EVENT_BEGAN;
EVENT_BEGAN := 13799;
% Convert the digits from a string to a numeric value.
numeric eventX;
eventX := lua("mp.print(userdata.parsetitle('getspecificstructuretitle3'))") ;
eventX := 1 - (eventX / EVENT_BEGAN);
numeric wb, hb ; wb := 3.33in ; hb := .33in ;
pickup pencircle scaled 2pt;
picture p ; p := image(
% Draw the line.
draw (0, .5*hb) -- (wb, .5*hb) ;
% Draw starting |.
draw (0, 0) -- (0, hb) ;
% Draw ending |.
draw (wb, 0) -- (wb, hb) ;
% Draw the timeline's dot relative to the event on the timeline.
filldraw fullcircle scaled 9 shifted (eventX * wb, .5*hb);
);
numeric h ; h := OverlayHeight ;
draw p shifted (-.33in, h - hb - .33in);
setbounds currentpicture to OverlayBox ;
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
edited 3 hours ago
answered 4 hours ago
Henri MenkeHenri Menke
78.1k8171285
78.1k8171285
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Why don't you draw the rule as part of
setuphead
? Why do you try usefor line continuation? MetaPost scans until a semicolon and
is actually a TeX control sequence which expands to a blank space.
– Henri Menke
4 hours ago