GitbookIO / gitbook

The open source frontend for GitBook doc sites
https://www.gitbook.com
GNU General Public License v3.0
27.17k stars 3.87k forks source link

gitbook pdf Error: TypeError: speech.processExpression is not a function #1875

Closed linrongbin16 closed 7 months ago

linrongbin16 commented 7 years ago

What is the current behavior?

gitbook serve for website works good. while gitbook pdf . ../mybook.pdf for pdf failed.

the book github repository is: https://github.com/zhaochenyou/Way-to-Algorithm

debug log:

debug: generate page "docs/Sort/InsertSort/README.md"
debug: calling hook "page:before"
warn: "this.generator" property is deprecated, use "this.output.name" instead
warn: "navigation" property is deprecated
warn: "book" property is deprecated, use "this" directly instead
Error: TypeError: speech.processExpression is not a function
    at GetSpeech (/Users/linrongbin/devenv/project/Way-to-Algorithm/node_modules/gitbook-plugin-mathjax/node_modules/mathjax-node/lib/mj-single.js:540:29)
    at Function.execute (file:///Users/linrongbin/devenv/project/Way-to-Algorithm/node_modules/mathjax/unpacked/MathJax.js:243:26)
    at cb (file:///Users/linrongbin/devenv/project/Way-to-Algorithm/node_modules/mathjax/unpacked/MathJax.js:225:59)
    at Object.Process (file:///Users/linrongbin/devenv/project/Way-to-Algorithm/node_modules/mathjax/unpacked/MathJax.js:495:38)
    at Object.call (file:///Users/linrongbin/devenv/project/Way-to-Algorithm/node_modules/mathjax/unpacked/MathJax.js:508:37)
    at Function.WAITEXECUTE (file:///Users/linrongbin/devenv/project/Way-to-Algorithm/node_modules/mathjax/unpacked/MathJax.js:348:50)
    at cb (file:///Users/linrongbin/devenv/project/Way-to-Algorithm/node_modules/mathjax/unpacked/MathJax.js:225:59)
    at Object.Process (file:///Users/linrongbin/devenv/project/Way-to-Algorithm/node_modules/mathjax/unpacked/MathJax.js:495:38)
    at Object.call (file:///Users/linrongbin/devenv/project/Way-to-Algorithm/node_modules/mathjax/unpacked/MathJax.js:508:37)
    at Function.WAITEXECUTE (file:///Users/linrongbin/devenv/project/Way-to-Algorithm/node_modules/mathjax/unpacked/MathJax.js:348:50)

Environment

MacOS: 10.12.6 CLI version: 2.3.2 GitBook version: 3.2.3 node version: v8.5.0 npm version: 5.5.1

What is the expected behavior?

gitbook pdf . ../mybook.pdf create a good pdf.

Gitbook URL

https://zhaochenyou.gitbooks.io/way-to-algorithm/content/

Thanks for your notice

0nse commented 6 years ago

I think we might face a similar bug due to using the mathjax plugin. Building works fine but rendering a PDF leads to the follwing error message:

info: 9 plugins are installed 
info: 7 explicitly listed 
info: loading plugin "toc"... OK 
info: loading plugin "mathjax"... OK 
info: loading plugin "highlight"... OK 
info: loading plugin "search"... OK 
info: loading plugin "lunr"... OK 
info: loading plugin "fontsettings"... OK 
info: loading plugin "theme-default"... OK 
info: found 7 pages 
info: found 8 asset files 
warn: "options" property is deprecated, use config.get(key) instead 
warn: "this.generator" property is deprecated, use "this.output.name" instead 
warn: "navigation" property is deprecated 
warn: "book" property is deprecated, use "this" directly instead 
SVG - Unknown character: U+20AC in MathJax_Main,MathJax_Size1,MathJax_AMS
Error: TypeError: speech.processExpression is not a function
    at GetSpeech ($HOME/docs/node_modules/mathjax-node/lib/mj-single.js:540:29)
    at Function.execute (file://$HOME/docs/node_modules/mathjax/unpacked/MathJax.js:243:26)
    at cb (file://$HOME/docs/node_modules/mathjax/unpacked/MathJax.js:225:59)
    at Object.Process (file://$HOME/docs/node_modules/mathjax/unpacked/MathJax.js:495:38)
    at Object.call (file://$HOME/docs/node_modules/mathjax/unpacked/MathJax.js:508:37)
    at Function.WAITEXECUTE (file://$HOME/docs/node_modules/mathjax/unpacked/MathJax.js:348:50)
    at cb (file://$HOME/docs/node_modules/mathjax/unpacked/MathJax.js:225:59)
    at Object.Process (file://$HOME/docs/node_modules/mathjax/unpacked/MathJax.js:495:38)
    at Object.call (file://$HOME/docs/node_modules/mathjax/unpacked/MathJax.js:508:37)
    at Function.WAITEXECUTE (file://$HOME/docs/node_modules/mathjax/unpacked/MathJax.js:348:50)
Li-Simon commented 6 years ago

Did you solved this problem?I met the same error, but I don't know how to solve it.

0nse commented 6 years ago

Unfortunately, I have not.

allenyllee commented 6 years ago

Hi, you can try my modified katex plugin allenyllee/plugin-katex: Math typesetting using KaTex

It can build and render pdf without error, but still have some format issue...

It can correctly display this: $$ o_j=softmax(z_j)=\frac{e^{z_j}}{\sum_j e^{z_j}} $$ but can not do for this: $$ z_j=\sumi w{ij} y_i+b_j $$ very strange...

If someone can fix it, please let me know. Thanks!

kachkaev commented 6 years ago

My solution: replace "mathjax" with "mathjax@https://github.com/OrgVue/gitbook-plugin-mathjax.git#speech-fix" in book.json.

The issue is caused by a breaking change in speech-rule-engine@2 that was released in August 2017. GitBook plugin mathjax requires mathjax-node@0.5.2, which in turn requires speech-rule-engine@* (simply the latest version).

My fork freezes speech-rule-engine to v1, which resolves speech.processExpression is not a function (this method was removed in speech-rule-engine@2).

loretoparisi commented 6 years ago

@kachkaev thank you, it started working in that way:

└─┬ gitbook-plugin-mathjax@1.1.2  (git+https://github.com/kachkaev/plugin-mathjax.git#c59540b44a4958c8364b0a88db88ae6caefe5c9b)
  └─┬ speech-rule-engine@1.2.0 
    ├── xmldom@0.1.27 
    └── xpath@0.0.27 

but now I have a

$ gitbook pdf ./ ./turicreate_userguide.pdf
info: 10 plugins are installed 
info: 9 explicitly listed 
info: loading plugin "collapsible-menu"... OK 
info: loading plugin "anchors"... OK 
info: loading plugin "mathjax"... OK 
info: loading plugin "highlight"... OK 
info: loading plugin "search"... OK 
info: loading plugin "lunr"... OK 
info: loading plugin "sharing"... OK 
info: loading plugin "fontsettings"... OK 
info: loading plugin "theme-default"... OK 
info: found 62 pages 
info: found 110 asset files 
warn: "sections" property is deprecated, use page.content instead 
warn: "this.generator" property is deprecated, use "this.output.name" instead 
warn: "navigation" property is deprecated 
warn: "book" property is deprecated, use "this" directly instead 
warn: "options" property is deprecated, use config.get(key) instead 
error: error while generating page "supervised-learning/logistic-regression.md": 

Error: Error converting /var/folders/_b/szqwdfn979n4fdg7f2j875_r0000gn/T/tmp-52146TyBvM1IdOHj9/_mathjax_90c24f7.svg into /var/folders/_b/szqwdfn979n4fdg7f2j875_r0000gn/T/tmp-52146TyBvM1IdOHj9/81e460b8.png

I have installed npm install svgexport -g that was required. This issue seems related to https://github.com/mobxjs/mobx/issues/397 actually.

tiansiyuan commented 5 years ago

@kachkaev Thank you. I got something as below:

➜ md version git:(master) ✗ gitbook install info: installing 1 plugins using npm@3.9.2 info: info: installing plugin "mathjax" info: install plugin "mathjax" (https://github.com/OrgVue/gitbook-plugin-mathjax.git#speech-fix) from NPM with version https://github.com/OrgVue/gitbook-plugin-mathjax.git#speech-fix

info: >> plugin "mathjax" installed with success ➜ md version git:(master) ✗ gitbook pdf info: 9 plugins are installed info: 7 explicitly listed info: loading plugin "mathjax"... OK info: loading plugin "highlight"... OK info: loading plugin "search"... OK info: loading plugin "lunr"... OK info: loading plugin "sharing"... OK info: loading plugin "fontsettings"... OK info: loading plugin "theme-default"... OK info: found 19 pages info: found 35 asset files warn: "this.generator" property is deprecated, use "this.output.name" instead warn: "navigation" property is deprecated warn: "book" property is deprecated, use "this" directly instead warn: "options" property is deprecated, use config.get(key) instead SVG - Unknown character: U+FF08 in MathJax_Main,MathJax_Size1,MathJax_AMS SVG - Unknown character: U+FF09 in MathJax_Main,MathJax_Size1,MathJax_AMS SVG - Unknown character: U+FF08 in MathJax_Main,MathJax_Size1,MathJax_AMS SVG - Unknown character: U+FF09 in MathJax_Main,MathJax_Size1,MathJax_AMS SVG - Unknown character: U+FF08 in MathJax_Main,MathJax_Size1,MathJax_AMS SVG - Unknown character: U+FF09 in MathJax_Main,MathJax_Size1,MathJax_AMS error: error while generating page "Chapter 1.md":

Error: Error with command "svgexport"