Re: [NTG-context] SVG text alignment issue
Thanks for checking this. Unfortunately, introducing \hbox didn't work; the text is still off-center with respect to the vertical line: https://i.ibb.co/hYGfdgZ/text-align.png For comparison, the SVG file loaded into Inkscape appears similar to: https://i.ibb.co/KF3PBkw/inkscape-alignment.png Note how the text is vertically centered above the vertical line. To me, it looks like the text, after a rotational transform, is being written to the baseline rather than (cap height + descender height) / 2, which seems to be a MetaPost conversion issue? There's another, possibly related issue, which I'll provide in a separate thread. Here's the code: % SOF \pushoverloadmode \unprotect \permanent\tolerant\protected\def\includesvgfile[#1]#*[#2]% {\hbox\bgroup % no \dontleavehmode \getdummyparameters[\c!offset=\zeropoint,#2]% \clf_includesvgfile{#1}\dimexpr\dummyparameter\c!offset\relax \egroup} \permanent\tolerant\protected\def\includesvgbuffer[#1]#*[#2]% {\hbox\bgroup % no \dontleavehmode \getdummyparameters[\c!offset=\zeropoint,#2]% \clf_includesvgbuffer{#1}\dimexpr\dummyparameter\c!offset\relax \egroup} \protect \popoverloadmode \startbuffer[svg] http://www.w3.org/2000/svg; xmlns:svg="http://www.w3.org/2000/svg;> 16p13.3 \stopbuffer \starttext \placefigure[]{}{\includesvgbuffer[svg][conversion=mp]} \stoptext % EOF ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] SVG text alignment issue
On 6/29/2022 4:35 AM, Aditya Mahajan via ntg-context wrote: On Mon, 27 Jun 2022, Thangalin via ntg-context wrote: In the following example, the line and text should be aligned to the middle when LMTX converts the SVG figure using MP. (Note that you may have to install Roboto, but the font isn't the issue.) % SOF \startbuffer[svg] http://www.w3.org/2000/svg; xmlns:svg="http://www.w3.org/2000/svg;> 16p13.3 \stopbuffer \starttext \placefigure[]{}{\includesvgbuffer[svg][conversion=mp]} \stoptext % EOF This has nothing to do with SVG. Looking at the definition of \includesvgbuffer, here is a simpler example illustrating the issue: \starttext \startplacefigure[location=here, title={Test}] \dontleavehmode\begingroup \startMPcode draw fullcircle scaled 2cm; \stopMPcode\endgroup \stopplacefigure \stoptext One way to "fix" the alignment is to wrap everything in an hbox: \placefigure[]{}{\hbox{\includesvgbuffer[svg][conversion=mp]}} Maybe there is a simple way to modify the definition of includesvgbuffer so that an \hbox is not needed. Thanks for checking it. Can you test with \pushoverloadmode \unprotect \permanent\tolerant\protected\def\includesvgfile[#1]#*[#2]% {\hbox\bgroup % no \dontleavehmode \getdummyparameters[\c!offset=\zeropoint,#2]% \clf_includesvgfile{#1}\dimexpr\dummyparameter\c!offset\relax \egroup} \permanent\tolerant\protected\def\includesvgbuffer[#1]#*[#2]% {\hbox\bgroup % no \dontleavehmode \getdummyparameters[\c!offset=\zeropoint,#2]% \clf_includesvgbuffer{#1}\dimexpr\dummyparameter\c!offset\relax \egroup} \protect \popoverloadmode Hans - Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl - ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] SVG images inside XML setups
Here's a fairly minimal example showing an issue, using ConTeXt LMTX. Save the following as "main.tex": % SOF \startbuffer[document] \stopbuffer \startbuffer[csvg] http://www.w3.org/2000/svg;> \stopbuffer \startxmlsetups xml:xhtml \xmlsetsetup{\xmldocument}{body|img}{xml:*} \stopxmlsetups \startxmlsetups xml:body \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:img \placefigure{}{\externalfigure[\xmlatt{#1}{src}][conversion=mp]} \placefigure{}{\externalfigure[circle.svg][conversion=mp]} \placefigure{}{\includesvgbuffer[csvg][conversion=mp]} \stopxmlsetups \xmlregistersetup{xml:xhtml} \starttext \xmlprocessbuffer{xhtml}{document}{} \placefigure{}{\externalfigure[circle.svg][conversion=mp]} \placefigure{}{\externalfigure[diagram.svg][conversion=mp]} \stoptext % EOF Save the contents of "\startbuffer[csvg]" to a file named "circle.svg", to create a valid, external SVG file. Copy "circle.svg" to a file named "diagram.svg" to create a second valid, external SVG file. Run: context main.tex Expected All the SVG images appear. Actual Figures 1, 2, and 4 show only the following text: \includesvgfile[circle.svg]\resetbuffer[svg-circle-inclusion] In contrast, consider the following document: % SOF \startbuffer[csvg] http://www.w3.org/2000/svg;> \stopbuffer \starttext \placefigure{}{\includesvgbuffer[csvg][conversion=mp]} \placefigure{}{\externalfigure[circle.svg][conversion=mp]} \placefigure{}{\externalfigure[diagram.svg][conversion=mp]} \stoptext % EOF All the images appear as expected. Any idea why using XML setups appears to affect the behaviour of rendering SVG documents using MetaPost? Thank you! ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] LMTX MetaFun SVG trouble, a portion of the SVG is cut of in the PDF
On 12/17/2020 3:03 PM, Neven Sajko wrote: Hello all, I am completely new to TeX, ConTeXt, MetaPost, etc. (Except for some MathJax snippets and the like.) I am using Aditya's LMTX package from AUR on Archlinux. I have some SVGs (generated by the Julia Gadfly package) that represent 2D plots of some functions, and I would like to include the SVGs in a ConTeXt document so it ends up as PDF. I started creating the document by including the SVGs using the new LMTX MetaPost SVG feature, however at this point I don't know how to proceed... This is the situation: the source SVGs look fine, but after including them in the document with the new ConTeXt feature mentioned above, the bottom-most part of the image is "cut off" (not visible). In the attached ZIP I included all relevant files (.tex, .svg, .pdf, ...), as well as PNG screenshots of the PDFs (in case the issue is PDF-viewer-specific, I'm using Chromium as the PDF viewer). I tried doing this in two different ways: using includesvgfile with the offset option, and using startMPcode with setbounds in the MetaFun code. In both cases I just get blank space instead of the cut-off content How can I fix this? Related question: is it possible to get the MetaPost code that (I think) the SVG gets translated to? I'm interested in how it looks like. \enabletrackers[metapost.svg.result] but i have a fix that does clipping different - Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl - ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] LMTX MetaFun SVG trouble, a portion of the SVG is cut of in the PDF
On Thu, 17 Dec 2020 at 15:27, Aditya Mahajan wrote: > OT but can Gadfly directly produce PDFs? [...] Yes it can. Going to try that route if this doesn't work out. > [..] Depending on how complicated plots you want to generate, you can also > use metapost graph module or pdfplots package for drawing 2D plots. OT, but that wouldn't work for me easily, because I don't actually know what function I'm plotting - it's a probability density function estimation (which is similar to a histogram, but continuous), where I only provide the data points and Gadfly takes care of everything else. > Can you check with a desktop pdf viewer as well. It looks the same with MuPDF. > The mailing list has a size limit for attachments, so I think that your zip > file did not get included in your message. Could you just include the tex > file and maybe upload the svg somewhere and include a link. This is a combined TeX file containing two different ways I took to try to accomplish the same thing: \starttext {\switchtobodyfont[2pt] {\framed[offset=overlay]{\includesvgfile[../hammingCoderStopwatch-hammingCoder-gcc-RowsSparse-1023-1013.svg][offset=20pt]}} {some offset} \startMPcode draw lmt_svg [ filename = "../hammingCoderStopwatch-hammingCoder-gcc-RowsSparse-1023-1013.svg" ]; setbounds currentpicture to boundingbox currentpicture enlarged 20pt; \stopMPcode } \stoptext The SVG: https://drive.google.com/file/d/1_JsIfA9cgEs5_x7FFJrUWPPe3Ht8JnIm/view?usp=sharing To be specific, what gets cut off is the bottom half of each number on the x-axis and the entire x-axis label. Thanks, Neven ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] LMTX MetaFun SVG trouble, a portion of the SVG is cut of in the PDF
On Thu, 17 Dec 2020, Neven Sajko wrote: > Hello all, > > I am completely new to TeX, ConTeXt, MetaPost, etc. (Except for some > MathJax snippets and the like.) > > I am using Aditya's LMTX package from AUR on Archlinux. > > I have some SVGs (generated by the Julia Gadfly package) that > represent 2D plots of some functions, and I would like to include the > SVGs in a ConTeXt document so it ends up as PDF. OT but can Gadfly directly produce PDFs? Depending on how complicated plots you want to generate, you can also use metapost graph module or pdfplots package for drawing 2D plots. > I started creating > the document by including the SVGs using the new LMTX MetaPost SVG > feature, however at this point I don't know how to proceed... > > This is the situation: the source SVGs look fine, but after including > them in the document with the new ConTeXt feature mentioned above, the > bottom-most part of the image is "cut off" (not visible). In the > attached ZIP I included all relevant files (.tex, .svg, .pdf, ...), as > well as PNG screenshots of the PDFs (in case the issue is > PDF-viewer-specific, I'm using Chromium as the PDF viewer). Can you check with a desktop pdf viewer as well. > I tried doing this in two different ways: using includesvgfile with > the offset option, and using startMPcode with setbounds in the MetaFun > code. In both cases I just get blank space instead of the cut-off > content > > How can I fix this? The mailing list has a size limit for attachments, so I think that your zip file did not get included in your message. Could you just include the tex file and maybe upload the svg somewhere and include a link. Aditya ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
[NTG-context] LMTX MetaFun SVG trouble, a portion of the SVG is cut of in the PDF
Hello all, I am completely new to TeX, ConTeXt, MetaPost, etc. (Except for some MathJax snippets and the like.) I am using Aditya's LMTX package from AUR on Archlinux. I have some SVGs (generated by the Julia Gadfly package) that represent 2D plots of some functions, and I would like to include the SVGs in a ConTeXt document so it ends up as PDF. I started creating the document by including the SVGs using the new LMTX MetaPost SVG feature, however at this point I don't know how to proceed... This is the situation: the source SVGs look fine, but after including them in the document with the new ConTeXt feature mentioned above, the bottom-most part of the image is "cut off" (not visible). In the attached ZIP I included all relevant files (.tex, .svg, .pdf, ...), as well as PNG screenshots of the PDFs (in case the issue is PDF-viewer-specific, I'm using Chromium as the PDF viewer). I tried doing this in two different ways: using includesvgfile with the offset option, and using startMPcode with setbounds in the MetaFun code. In both cases I just get blank space instead of the cut-off content How can I fix this? Related question: is it possible to get the MetaPost code that (I think) the SVG gets translated to? I'm interested in how it looks like. Thanks, Neven ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Label in externalfigures
Now finally after consulting the luametafun and the MetaFun manual I’ve found what I was looking for:The code:\startMPcode picture p; p := lmt_svg [ filename = "steguppgift.svg", width = 400 ] ;draw p;path linje ; linje := (15,-330) -- (280,-90); % adding a missing line in the .svg filedrawarrow linje withcolor black ;draw thelabel("37°",(160,-330));draw thelabel("$5,0$m",(150,-160));\stopMPcodeThis was a fun learning experience so thanks again13 feb. 2020 kl. 10:35 skrev Jan-Erik Hägglöf <janerik.hagg...@bahnhof.se>:I’ve tested this but it appears outside, not as an layer over the picture.\startMPcode draw lmt_svg [ filename = "steguppgift.svg", height = 5cm, width = 10cm, ] ;label(\sometxt{5,0m},(63.936298,129.563995));label(\sometxt{37°},(95.652702,27.367201)); \stopMPcodeThanks /Janne12 feb. 2020 kl. 20:10 skrev Hans Hagen <j.ha...@xs4all.nl>:On 2/12/2020 6:01 PM, Jan-Erik Hägglöf wrote:The expected output should be like this, see example in the link belowhttps://drive.google.com/file/d/13pCuUvNeL7T_Hs7-qrKZclkadcJ7_jVV/view?usp=sharingSo that I have a picture so I can change the label text inside according to different needs e.g change from 37° to 41° without reediting it in Inkscape.A similar properties like latex export picture.pdf_tex which is a function in InkscapeI investigate the details manual tip you provided, thanks a lot.you might want to peek into the luametafun manual as svg is discussed there, including label stuffwhat you can also try (with lmtx) is this (no real interface yet):\starttext\hbox\bgroup \ctxlua{metapost.startsvghashing()}% \includesvgfile[labels-004.svg]% \ctxlua{metapost.stopsvghashing()}%\egroup\stoptextwhich should turn your labels into tex, so you can typeset them as tex (so $\\sin(x)$ comes out as math) it's no big deal to add a remap option there but then i'd rather go for symbolic namesHans- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl-___If your question is of interest to others as well, please add an entry to the Wiki!maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-contextwebpage : http://www.pragma-ade.nl / http://context.aanhet.netarchive : https://bitbucket.org/phg/context-mirror/commits/wiki : http://contextgarden.net__ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Label in externalfigures
I’ve tested this but it appears outside, not as an layer over the picture. \startMPcode draw lmt_svg [ filename = "steguppgift.svg", height = 5cm, width = 10cm, ] ; label(\sometxt{5,0m},(63.936298,129.563995)); label(\sometxt{37°},(95.652702,27.367201)); \stopMPcode Thanks /Janne > 12 feb. 2020 kl. 20:10 skrev Hans Hagen : > > On 2/12/2020 6:01 PM, Jan-Erik Hägglöf wrote: >> The expected output should be like this, see example in the link below >> https://drive.google.com/file/d/13pCuUvNeL7T_Hs7-qrKZclkadcJ7_jVV/view?usp=sharing >> So that I have a picture so I can change the label text inside according to >> different needs e.g change from 37° to 41° without reediting it in Inkscape. >> A similar properties like latex export picture.pdf_tex which is a function >> in Inkscape >> I investigate the details manual tip you provided, thanks a lot. > you might want to peek into the luametafun manual as svg is discussed there, > including label stuff > > what you can also try (with lmtx) is this (no real interface yet): > > \starttext > > \hbox\bgroup > \ctxlua{metapost.startsvghashing()}% > \includesvgfile[labels-004.svg]% > \ctxlua{metapost.stopsvghashing()}% > \egroup > > \stoptext > > which should turn your labels into tex, so you can typeset them as tex (so > $\\sin(x)$ comes out as math) it's no big deal to add a remap option there > but then i'd rather go for symbolic names > > Hans > > - > Hans Hagen | PRAGMA ADE > Ridderstraat 27 | 8061 GH Hasselt | The Netherlands > tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl > - ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___
Re: [NTG-context] Label in externalfigures
On 2/12/2020 6:01 PM, Jan-Erik Hägglöf wrote: The expected output should be like this, see example in the link below https://drive.google.com/file/d/13pCuUvNeL7T_Hs7-qrKZclkadcJ7_jVV/view?usp=sharing So that I have a picture so I can change the label text inside according to different needs e.g change from 37° to 41° without reediting it in Inkscape. A similar properties like latex export picture.pdf_tex which is a function in Inkscape I investigate the details manual tip you provided, thanks a lot. you might want to peek into the luametafun manual as svg is discussed there, including label stuff what you can also try (with lmtx) is this (no real interface yet): \starttext \hbox\bgroup \ctxlua{metapost.startsvghashing()}% \includesvgfile[labels-004.svg]% \ctxlua{metapost.stopsvghashing()}% \egroup \stoptext which should turn your labels into tex, so you can typeset them as tex (so $\\sin(x)$ comes out as math) it's no big deal to add a remap option there but then i'd rather go for symbolic names Hans - Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl - ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___