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

How to config it to make it work? #26

Closed
ChenZhongPu opened this issue Apr 6, 2016 · 28 comments
Closed

How to config it to make it work? #26

ChenZhongPu opened this issue Apr 6, 2016 · 28 comments

Comments

@ChenZhongPu
Copy link

After installing it, I just add the followings to _config.xml

math:
  engine: 'mathjax' # or 'katex'
  mathjax:
    src: custom_mathjax_source
    config:
      # MathJax config
  katex:
    css: custom_css_source
    js: custom_js_source # not used
    config:
      # KaTeX config

When I run it:

 ~/Project/gitwork/blogGitPage  hexo s
INFO  [hexo-math] Using engine 'mathjax'
INFO  Hexo is running at http://0.0.0.0:4000/. Press Ctrl+C to stop.

However, the Simple inline $a = b + c$. is not displayed in math format.

Do I config it correctly?

@akfish
Copy link
Member

akfish commented Apr 7, 2016

Normally you don't need to add anything in your _config.yml. It works by default.
If you do need a different MathJax script source other than its official CDN, you should provide a valid math.mathjax.src value. Your current configuration is custom_mathjax_source, which is not valid.

Remove all your configuration will fix your problem.

@akfish akfish added the question label Apr 7, 2016
@ChenZhongPu
Copy link
Author

Now I have removed the configuration, but it still does not work. Do I need to do other else work after npm install hexo-math --save? By the way, the version of hexo is 3.1.1 and I use a third-party theme.

@akfish
Copy link
Member

akfish commented Apr 7, 2016

What's the generated HTML looks like?

@akfish
Copy link
Member

akfish commented Apr 7, 2016

And also your site's package.json?

@ChenZhongPu
Copy link
Author

The package.json:

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "hexo": {
    "version": "3.1.1"
  },
  "dependencies": {
    "hexo": "^3.1.1",
    "hexo-deployer-git": "0.0.4",
    "hexo-generator-archive": "^0.1.3",
    "hexo-generator-category": "^0.1.3",
    "hexo-generator-index": "^0.2.0",
    "hexo-generator-tag": "^0.1.2",
    "hexo-inject": "^1.0.0",
    "hexo-math": "^3.0.1",
    "hexo-renderer-ejs": "^0.1.0",
    "hexo-renderer-jade": "^0.1.0",
    "hexo-renderer-marked": "^0.2.6",
    "hexo-renderer-mathjax": "^0.6.0",
    "hexo-renderer-sass": "^0.2.0",
    "hexo-renderer-stylus": "^0.3.0",
    "hexo-server": "^0.1.2"
  }
}

Do I need add

plugins:
 - hexo-math

in _config.xml ?

@akfish
Copy link
Member

akfish commented Apr 7, 2016

Try run hexo clean first see if that will fix it.

@ChenZhongPu
Copy link
Author

It still does not works.

@akfish
Copy link
Member

akfish commented Apr 7, 2016

What's the generated HTML looks like?

@ChenZhongPu
Copy link
Author

@ChenZhongPu
Copy link
Author

Currently, the _config.xml

# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: 陈中普
subtitle: Zhongpu Chen's Blog
description:
author: Zhongpu Chen
language: zh-CN
timezone:

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://chenzhongpu.github.io
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:

# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render: [README.md, 404.html, about/time.html]

# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
  enable: true
  line_number: true
  auto_detect: true
  tab_replace:

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss

# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: maupassant


# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: git
  repo: https://github.com/ChenZhongPu/ChenZhongPu.github.io.git
  branch: master

@akfish
Copy link
Member

akfish commented Apr 7, 2016

It seems to be a compatibility issue between hexo-inject and hexo-renderer-jade. I'll look into it further once I'm free.

@zqchen90
Copy link

zqchen90 commented Apr 7, 2016

With the same problem

@ziyuang
Copy link

ziyuang commented Apr 9, 2016

Can I switch to other renderers if hexo-renderer-jade is the culprit?

@akfish
Copy link
Member

akfish commented Apr 9, 2016

@ziyuang Sure. hexo-inject is tested with built-in swig renderer and hexo-renderer-ejs. But you are stuck with your theme developer's choice.

@ziyuang
Copy link

ziyuang commented Apr 9, 2016

@akfish I am using the default landscape theme. It looks to me that it uses EJS not Jade since all files under themes/landscape/layout are with extension .ejs.

My _config.yml:

(site info omitted)

# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:

# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: true
relative_link: false
future: true
highlight:
  enable: true
  line_number: true
  auto_detect: false
  tab_replace:

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss

# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: landscape

math:
  engine: 'katex'
  katex:
    css: #custom_css_source
    js: # not used
    config:
      # KaTeX config

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type:

and the package.json:

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "hexo": {
    "version": "3.1.1"
  },
  "dependencies": {
    "hexo": "^3.1.1",
    "hexo-generator-archive": "^0.1.4",
    "hexo-generator-category": "^0.1.3",
    "hexo-generator-index": "^0.2.0",
    "hexo-generator-tag": "^0.2.0",
    "hexo-inject": "^1.0.0",
    "hexo-math": "^3.0.1",
    "hexo-renderer-ejs": "^0.1.1",
    "hexo-renderer-marked": "^0.2.9",
    "hexo-renderer-stylus": "^0.3.0",
    "hexo-server": "^0.1.3"
  }
}

I notice in the generated HTML file there is <!-- hexo-inject:begin --><!-- hexo-inject:end -->, which means no infect is happening if I understand correctly.

@ziyuang
Copy link

ziyuang commented Apr 10, 2016

OK, after clearing the whole math: part in _config.yml, the rendering is fine (with MathJax). But it looks to me that I have to escape _ and \ sometimes:

$$
\\begin{aligned}
x\_{f} = & x\_0+k(x-x\_0) \\\\
y\_{f} = & y\_0+k(y-y\_0) \\\\
s\_{f} = & k
\\end{aligned}
$$

This is not happening in inline mode.

@akfish
Copy link
Member

akfish commented Apr 10, 2016

@ziyuang You will have to escape special characters with$...$ and $$...$$ syntax depending on the Markdown renderer you are using, They are not processed by hexo-math. The rendering of those syntax is provided by MathJax, which runs in browser.
{% math %}...{% endmath %} will not have those issues.

@fusion809
Copy link

fusion809 commented Apr 21, 2016

This plugin repeatedly failed for me, no matter what I did to _config.yml or how I inserted math into documents or whether I ran hexo clean first before starting the server and generating. This is why I am here to recommend if anyone is still finding that this plugin is failing for them that they use the hexo-renderer-mathjax plugin instead as for me it worked as soon as I ran npm install hexo-renderer-mathjax --save from my Hexo site's root folder.

@pcwerk
Copy link

pcwerk commented Aug 23, 2016

@fusion809 looks good

npm install hexo-renderer-mathjax --save

Appears to work. Thanks!

@Haojen
Copy link

Haojen commented Jul 14, 2017

i have this problem too

@D0048
Copy link

D0048 commented Oct 14, 2017

Encountering the same here.

@godshen
Copy link

godshen commented Oct 30, 2017

3rd edit

there is a new problem that is
when i deploy my site on username.github.io
the browser told me that the script which render the mathematical formula is unsafety
so when anyone brows my site they have to click load the script


2nd eidt

finally i got it!!!
i changed my _config.yml like this

which means that there is no source files named "custom_mathjax_source" in local
so these codes should be commentted out and then it works

math:
 engine: 'mathjax' # or 'katex'
  mathjax:
   src: #custom_mathjax_source
    config:
      # MathJax config

   katex:
    css: #custom_css_source
    js: #custom_js_source # not used
    config:
      # KaTeX config

1st edit

this problem bothered me few days, who can help me

@CntChen
Copy link

CntChen commented Nov 1, 2017

the following config in _config.yml works for me:

math:
  engine: 'mathjax' # or 'katex'
  mathjax:
    src: "//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
    config:
      # MathJax config
  katex:
    css: #custom_css_source
    js: #custom_js_source # not used
    config:
      # KaTeX config

set math.mathjax.src as //cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML as mentioned in README.md

@lonelyWaiting
Copy link

lonelyWaiting commented Nov 22, 2017

i have this problem too.but now it works.
After installing the plug-in I did not find the hexo-math folder.
then i install hexo-renderer-mathjax
now i found hexo-math folder under node_modules directory
But still can not work.
open node_modules\hexo-math\lib\option.js

var DEFAULT_OPTS = exports.DEFAULT_OPTS = {
  engine: 'mathjax',
  mathjax: {
    src: "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js",
    config: {
      tex2jax: {
        inlineMath: [['$', '$'], ["\\(", "\\)"]],
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'],
        processEscapes: true
      },
      TeX: {
        equationNumbers: {
          autoNumber: "AMS"
        }
      }
    }
  },
  katex: {
    css: "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.5.1/katex.min.css",
    js: "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.5.1/katex.min.js",
    config: {
      throwOnError: false,
      errorColor: "#cc0000"
    }
  }
};

modify `mathjax/src'

var DEFAULT_OPTS = exports.DEFAULT_OPTS = {
  engine: 'mathjax',
  mathjax: {
    src: "//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML",
    config: {
      tex2jax: {
        inlineMath: [['$', '$'], ["\\(", "\\)"]],
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'],
        processEscapes: true
      },
      TeX: {
        equationNumbers: {
          autoNumber: "AMS"
        }
      }
    }
  },
  katex: {
    css: "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.5.1/katex.min.css",
    js: "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.5.1/katex.min.js",
    config: {
      throwOnError: false,
      errorColor: "#cc0000"
    }
  }
};

now it works.

@NoahDragon
Copy link
Member

Close as many solutions have provided.

@ruicx
Copy link

ruicx commented Jan 28, 2018

This plugin can work in the theme NexT, but cannot work in any other themes. No matter what I do in _config.yml or change the markdowm enging. Thinks to @fusion809 I add the plugin hexo-renderer-mathjax and @lonelyWaiting I change the cdn fixed it.
Here is the ditails:

  1. Install hexo-renderer-mathjax
npm install hexo-renderer-mathjax --save
  1. Add to _config.yml
math:
  engine: 'mathjax' # or 'katex'
  mathjax:
    src: "//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
    config:
      # MathJax config
  katex:
    css: #custom_css_source
    js: #custom_js_source # not used
    config:
      # KaTeX config

Then, it will work.


Notice: DONOT uninstall hexo-math.

@weifengsd
Copy link

I think the hexo-renderer-mathjax is a better choise.
One modification should be made to mathjax.html to avoid a notification of safety problem.
<script src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

@b6514
Copy link

b6514 commented Aug 31, 2018

$ npm install hexo-tag-aplayer@3.0

  • hexo-tag-aplayer@3.0.4
    added 1 package from 1 contributor, removed 11 packages, updated 1 package, moved 1 package and audited 3829 packages in 4.985s
    found 1 low severity vulnerability
    run npm audit fix to fix them, or npm audit for details
    这是什么问题网页里面有声音但是播放器是散开的,放得很大

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

No branches or pull requests