Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MaTeX has problems with characters in wasysym package #40

Open
jmbryant12 opened this issue Jun 12, 2024 · 12 comments
Open

MaTeX has problems with characters in wasysym package #40

jmbryant12 opened this issue Jun 12, 2024 · 12 comments

Comments

@jmbryant12
Copy link

jmbryant12 commented Jun 12, 2024

Describe the bug

MaTex is unable to communicate with PDF.exe for characters in the wasysym package like \\leftmoon

To Reproduce

Needs["MaTeX`"]

In[34]:= MaTeX["M_{\\leftmoon }", "Preamble" -> {"\\usepackage{wasysym}"}]

During evaluation of In[33]:= LinkObject::linkd: Unable to communicate with closed link LinkObject["C:\Program Files\Wolfram Research\Mathematica\13.1\SystemFiles\Converters\Binaries\Windows-x86-64\PDF.exe",3156,37].

During evaluation of In[34]:= MaTeX::importerr: Failed to import PDF. This is unexpected. Please go to https://github.com/szhorvat/MaTeX and create a bug report.

Out[33]= $Failed
...

Additional information

  • MaTeX version: 1.7.10
  • Mathematica version: 13.1
  • OS version: Windows 10
@szhorvat
Copy link
Owner

This seems like a crash bug in Mathematica's PDF importer and should be reported to Wolfram.

Please send them the problematic PDF file. Use MaTeX`Developer`WorkingDirectory[] to get the location where the file will be written. Then use Block[{DeleteFile}, MaTeX["M_{\\leftmoon }", "Preamble" -> {"\\usepackage{wasysym}"}]] to prevent the file from being removed.

Note: This works fine for me on macOS with Mathematica 14.0, so maybe the bug was fixed, or maybe it's Windows-only.

@jmbryant12
Copy link
Author

jmbryant12 commented Jun 12, 2024

I did as you suggested and tried to Import the PDF and it worked fine (I put in a Print statement for my own info).
PDFImport

The path in the Import is shorter since I copied that PF file to my desktop, but the full path was:

Import["C:\\Users\\jeffb\\AppData\\Local\\Temp\\MaTeX_sfqozerazgzasgub\\pjxyyytyqlxtkyrj-gs.pdf"]

@jmbryant12
Copy link
Author

FWIW, I tried this in Mathematica 14.0 and it fails similar for me via MaTeX, but the Import works fine when I manually import the resulting PDF file

@jmbryant12
Copy link
Author

Ah, this reproduces it for me:

In[58]:= \
Import["C:\\Users\\jeffb\\AppData\\Local\\Temp\\MaTeX_\
sfqozerazgzasgub\\pjxyyytyqlxtkyrj-gs.pdf", {"PDF", "Pages"}]

During evaluation of In[58]:= LinkObject::linkd: Unable to communicate with closed link LinkObject["C:\Program Files\Wolfram Research\Mathematica\13.1\SystemFiles\Converters\Binaries\Windows-x86-64\PDF.exe",4650,37].

Out[58]= $Failed

Its that second argument causing the crash

@szhorvat
Copy link
Owner

szhorvat commented Jun 12, 2024

Thanks for debugging this! I am very busy at the moment and won't have the opportunity to look at this for ~2 weeks. I also don't have an easy way to test on Windows right now. If you could report this to Wolfram, that would be very useful. If they have useful suggestions, please report back here.

The difference between your machine and mine could be the OS (Windows vs macOS) or the font that's being used. Is the little moon pixelated for you after import, or smooth like here?

image

Let's get back to this in about 2 weeks, and see what workarounds we can come up with,

@jmbryant12
Copy link
Author

I reported it to Wolfram and it looks fuzzy to me when I import as "PDF"

@szhorvat
Copy link
Owner

I'm not sure this will help you at all for moving on with your work, but here's a vector version you can use ...

Graphics[{Thickness[0.04327131112072695], FilledCurve[{{{1, 4, 3}, {0, 1, 0}, {1, 3, 
   3}, {0, 1, 0}, {0, 1, 0}, {1, 3, 3}, {0, 1, 0}, {1, 3, 3}, {1, 3, 3}, {1, 3, 3}, {1, 
   3, 3}, {0, 1, 0}, {1, 3, 3}, {1, 3, 3}, {1, 3, 3}, {0, 1, 0}, {0, 1, 0}, {1, 3, 3}, 
   {1, 3, 3}, {1, 3, 3}, {1, 3, 3}, {1, 3, 3}, {0, 1, 0}, {0, 1, 0}, {0, 1, 0}, {1, 3, 
   3}, {1, 3, 3}, {0, 1, 0}, {0, 1, 0}, {0, 1, 0}, {1, 3, 3}, {1, 3, 3}, {1, 3, 3}, {1, 
   3, 3}, {0, 1, 0}, {1, 3, 3}, {1, 3, 3}, {1, 3, 3}, {1, 3, 3}, {1, 3, 3}, {0, 1, 0}, 
   {1, 3, 3}, {1, 3, 3}}}, {{{13.164099999999998, 13.340600000000002}, 
   {13.164099999999998, 13.460899999999995}, {13.0797, 13.460899999999995}, 
   {12.853099999999998, 13.460899999999995}, {11.418799999999997, 13.460899999999995}, 
   {11.1203, 13.460899999999995}, {11.107799999999997, 13.4484}, {10.9766, 
   13.257800000000001}, {6.6156299999999995, 6.364059999999999}, {5.720310000000001, 
   13.1984}, {5.684379999999999, 13.460899999999995}, {5.67188, 13.460899999999995}, 
   {5.360939999999999, 13.460899999999995}, {3.87969, 13.460899999999995}, 
   {3.6531299999999995, 13.460899999999995}, {3.5453099999999993, 13.460899999999995}, 
   {3.5453099999999993, 13.2344}, {3.5453099999999993, 13.1141}, {3.6531299999999995, 
   13.1141}, {3.8312499999999994, 13.1141}, {4.5609399999999996, 13.1141}, 
   {4.5609399999999996, 13.018799999999999}, {4.5609399999999996, 12.887500000000001}, 
   {4.560939999999999, 12.887500000000001}, {4.5609399999999996, 12.7922}, {4.5125, 
   12.612499999999997}, {2.9828099999999997, 6.518750000000001}, {2.8406299999999995, 
   5.945309999999999}, {2.5656300000000005, 5.68281}, {1.7640599999999997, 
   5.6468799999999995}, {1.72813, 5.6468799999999995}, {1.5859400000000001, 5.63438}, 
   {1.5859400000000001, 5.4312499999999995}, {1.5859400000000001, 5.300000000000001}, 
   {1.6937499999999996, 5.300000000000001}, {1.7406299999999995, 5.300000000000001}, 
   {2.82813, 5.32344}, {3.4015599999999995, 5.32344}, {3.5687499999999996, 5.32344}, 
   {3.7718799999999995, 5.300000000000001}, {3.9390599999999996, 5.300000000000001}, 
   {4.02344, 5.300000000000001}, {4.1546899999999996, 5.300000000000001}, 
   {4.1546899999999996, 5.52656}, {4.1546899999999996, 5.63438}, {4.034379999999999, 
   5.6468799999999995}, {3.9874999999999994, 5.6468799999999995}, {3.5921900000000004, 
   5.657810000000001}, {3.2109400000000003, 5.7296900000000015}, {3.2109400000000003, 
   6.160939999999999}, {3.2109400000000003, 6.27969}, {3.2109400000000003, 6.29219}, 
   {3.257810000000001, 6.4593799999999995}, {4.907810000000001, 13.042200000000001}, 
   {4.918749999999999, 13.042200000000001}, {5.91094, 5.621880000000001}, {5.94688, 
   5.335939999999999}, {5.95781, 5.300000000000001}, {6.06563, 5.300000000000001}, 
   {6.196879999999999, 5.300000000000001}, {6.25781, 5.395309999999999}, 
   {6.317189999999999, 5.50313}, {11.1203, 13.101599999999998}, {11.132799999999998, 
   13.101599999999998}, {9.399999999999999, 6.184379999999999}, {9.29219, 5.76563}, 
   {9.268749999999999, 5.6468799999999995}, {8.431249999999999, 5.6468799999999995}, 
   {8.20469, 5.6468799999999995}, {8.085939999999999, 5.6468799999999995}, 
   {8.085939999999999, 5.4312499999999995}, {8.085939999999999, 5.300000000000001}, 
   {8.192190000000002, 5.300000000000001}, {8.264059999999999, 5.300000000000001}, 
   {8.46719, 5.300000000000001}, {8.706249999999999, 5.32344}, {8.909379999999999, 
   5.32344}, {10.3203, 5.32344}, {10.523400000000002, 5.32344}, {10.773400000000002, 
   5.300000000000001}, {10.9766, 5.300000000000001}, {11.0719, 5.300000000000001}, 
   {11.2031, 5.300000000000001}, {11.2031, 5.52656}, {11.2031, 5.6468799999999995}, 
   {11.0969, 5.6468799999999995}, {10.917199999999998, 5.6468799999999995}, {10.1875, 
   5.6468799999999995}, {10.1875, 5.742190000000001}, {10.1875, 5.860939999999999}, 
   {10.1875, 5.860939999999999}, {10.1875, 5.95781}, {10.212499999999999, 
   6.0531299999999995}, {11.8484, 12.5891}, {11.956299999999999, 12.995299999999999}, 
   {11.9813, 13.1141}, {12.8281, 13.1141}, {13.0563, 13.1141}, {13.164099999999998, 
   13.1141}, {13.164099999999998, 13.340600000000002}}}], 
  FilledCurve[{{{1, 4, 3}, {1, 3, 3}, {1, 3, 3}, {1, 3, 3}, {1, 3, 3}, {1, 3, 3}}, {{1, 
    4, 3}, {1, 3, 3}, {1, 3, 3}, {1, 3, 3}, {1, 3, 3}, {1, 3, 3}, {1, 3, 3}, {1, 3, 3}, 
    {1, 3, 3}, {1, 3, 3}}}, {{{16.948400000000003, 1.8749999999999998}, {16.0391, 
    1.93438}, {15.167200000000001, 2.31563}, {14.449999999999998, 2.925}, 
    {13.757800000000001, 3.5109399999999997}, {13.446899999999998, 4.4312499999999995}, 
    {13.446899999999998, 5.387499999999999}, {13.446899999999998, 6.3421899999999996}, 
    {13.757800000000001, 7.262499999999999}, {14.449999999999998, 7.84844}, 
    {15.167200000000001, 8.45781}, {16.0391, 8.840629999999999}, {16.948400000000003, 
    8.899999999999999}, {16.004699999999996, 7.99219}, {15.454699999999997, 
    6.7250000000000005}, {15.454699999999997, 5.387499999999999}, {15.454699999999997, 
    4.0484399999999985}, {16.004699999999996, 2.7828099999999996}, {16.948400000000003, 
    1.8749999999999998}}, {{17.735899999999997, 1.8390599999999997}, {16.6016, 
    2.6624999999999996}, {15.9328, 3.976560000000001}, {15.9328, 5.387499999999999}, 
    {15.9328, 6.796880000000001}, {16.6016, 8.110939999999998}, {17.735899999999997, 
    8.93594}, {17.796899999999997, 8.982809999999999}, {17.832800000000002, 
    9.043750000000001}, {17.832800000000002, 9.139059999999999}, {17.832800000000002, 
    9.378129999999999}, {17.532800000000005, 9.389059999999999}, {17.3297, 
    9.389059999999999}, {16.1469, 9.389059999999999}, {15.059399999999997, 
    8.982809999999999}, {14.1406, 8.218749999999998}, {13.315600000000002, 7.51406}, 
    {12.957799999999999, 6.439060000000001}, {12.957799999999999, 5.387499999999999}, 
    {12.957799999999999, 4.33594}, {13.315600000000002, 3.2609399999999997}, {14.1406, 
    2.55469}, {15.059399999999997, 1.77813}, {16.1594, 1.3843800000000002}, 
    {17.342200000000002, 1.3843800000000002}, {17.509399999999996, 1.3843800000000002}, 
    {17.7, 1.3843800000000002}, {17.832800000000002, 1.6359399999999997}, 
    {17.832800000000002, 1.7062499999999998}, {17.807799999999997, 1.7906299999999995}, 
    {17.735899999999997, 1.8390599999999997}}}]}, AspectRatio -> Automatic, 
 BaselinePosition -> Scaled[0.32439307852814453], ImageSize -> {23.113962640099626, 
  16.338709838107096}, PlotRange -> {{0., 23.110000000000003}, {0., 16.34}}]

@jmbryant12
Copy link
Author

Instead of {"PDF", "Pages"} how does {"PDF", "PageImages"} work for you? That works/looks the same for me as just "PDF"

@jmbryant12
Copy link
Author

jmbryant12 commented Jun 12, 2024

According to Wolfram, {"PDF", "Pages"} was legacy undocumented functionality and bug fixes for that are unlikely. The default element for "PDF" Import is {"PDF", "PageImages"}. {"PDF", "PageGraphics"} also exists but it has a hard time with the PDF primitives used for the crescent moon so the results show the crescent moon as empty/whitespace.

@jmbryant12
Copy link
Author

"PageImages" was added in 12.2 along with a number of other updates.. "PageGraphics" was added and "Pages" was hidden in 13.0

@szhorvat
Copy link
Owner

Wow, you got an extremely fast response! Are you by any chance the same J Bryant who works at Wolfram|Alpha?

The response is disappointing ... we need vector for this, not images. And I'm pretty sure vector (what "Pages" does) used to be the default import option. I'll also ask WRI about this when I get the time to argue our case well ... MaTeX is very popular in some fields (e.g. physics), and it'd be a shame if a feature it critically depends on went away.

@jmbryant12
Copy link
Author

jmbryant12 commented Jun 12, 2024

Yes, I'm with Wolfram|Alpha.

The default changed in 12.2 when PageImages was added. Import[... "PDF"], starting in 12.2, is now Import[..., {"PDF", "PageImages"}]. Import[..., {"PDF", "PageGraphics"}] may not error, but it may contain an unsupported graphics primitive which render as blank

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants