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

Incorrect position of Chinese with XeLaTeX in TexLive #235

Closed
rehnertz opened this issue Mar 31, 2023 · 3 comments
Closed

Incorrect position of Chinese with XeLaTeX in TexLive #235

rehnertz opened this issue Mar 31, 2023 · 3 comments
Assignees
Labels
Milestone

Comments

@rehnertz
Copy link

With the following LaTeX code

\documentclass[preview]{standalone}
\usepackage[UTF8]{ctex}
\begin{document}
    \begin{center}
        Hello 你好 \LaTeX
    \end{center}
\end{document}

The output pdf of xelatex is correct:

pdf-output

However, when transforming xdv to svg, i.e.

xelatex -no-pdf main.tex
dvisvgm -n main.xdv

the Chinese characters are shifted:

svg-output

TexLive2023 on Windodws 11.

I'm using manim to build Maths videos, and I need to write Chinese with inline fomulae. I find out that manim uses dvisvgm -n XXXX.xdv to generate svg's for videos. It does not support outputs without the option -n. Whether or not manim uses other methods to solve this problem, I think this is still a bug in dvisvgm

@rehnertz rehnertz changed the title Incorrect position of Chinese with XeLaTeX Incorrect position of Chinese with XeLaTeX in TexLive Mar 31, 2023
@muzimuzhi
Copy link

muzimuzhi commented Mar 31, 2023

Just a workaround, if I feed pdf to dvisvgm then the baseline in svg is fine.

xelatex main.tex
dvisvgm --pdf -n main.pdf

PS: Your main.tex could be simplified to

\documentclass{standalone}
\usepackage{ctex}
\begin{document}
  Hello 你好 \LaTeX
\end{document}

@muzimuzhi
Copy link

It seems the mis-alignment only occurs with CJK fonts and the content in CJK fonts is vertically centered on some axis (perhaps the normal baseline), character by character.

% !TeX TS-program = xelatex
\documentclass{standalone}
\usepackage{fontspec}

\font\1="FandolHei"
\font\2="Latin Modern Mono"

\begin{document}
  \parbox{\linewidth}{
    Hello {\fontspec{FandolHei}FandolHei} World {\1FandolHei} \\
    Hello {\fontspec{Latin Modern Mono}LM Mono} World {\2LM Mono}
  }
\end{document}

PDF
image
SVG (generated from .xdv with -n option)
image

@mgieseki mgieseki self-assigned this Apr 11, 2023
@mgieseki mgieseki added the bug label Apr 11, 2023
@mgieseki
Copy link
Owner

Thanks for reporting the issue and thanks @muzimuzhi for posting the workaround. I've committed a quick fix that will hopefully work in most cases.

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

No branches or pull requests

3 participants