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

Asian text is not able to auto linebreak #93

Open
gingerkitti opened this issue Mar 16, 2022 · 12 comments
Open

Asian text is not able to auto linebreak #93

gingerkitti opened this issue Mar 16, 2022 · 12 comments

Comments

@gingerkitti
Copy link

Hello, I just met the problem that Asian text cannot be automatically linebreaked and that text goes off-page.

I am not a jlatexmath user directly, while I am a freeplane user. I met this problem and submitted the issue under freeplane's Issues. Contributor there suggest that I should report it here. The original issue is there: #freeplane/freeplane#263 (comment)

Cheers and Best Regards

@murkle
Copy link
Collaborator

murkle commented Mar 16, 2022

Doesn't sound like a jlatexmath bug as there's no automatic line-breaking support

In any case, you'll need to provide the exact LaTeX strings ("English" and "Asian") that you are sending to the library if you want us to check further

@fnatter
Copy link
Contributor

fnatter commented Mar 16, 2022

Doesn't sound like a jlatexmath bug as there's no automatic line-breaking support

hello murkle,

I am the (co)author of the Freeplane LaTeX plugin, and I am quite sure that JLaTeXMath supports automatic line breaking
using the TeXIconBuilder interface (inner class in TeXFormula.java, I introduced this a long time ago):

		return tf.new TeXIconBuilder()
			.setStyle(style)
			.setSize(size)
			.setWidth(TeXConstants.UNIT_PIXEL, maxWidth, align)
			.setIsMaxWidth(true)
//			.setInterLineSpacing(TeXConstants.UNIT_PIXEL, /*40f*/size * 1.2F)
			.setInterLineSpacing(latexInterlineSpacingUnit, latexInterlineSpacingValue)
			.build();

https://github.com/freeplane/freeplane/blob/1.9.x/freeplane_plugin_latex/src/main/java/org/freeplane/plugin/latex/TeXText.java#L72

Cheers and Best Regards,
Felix

@BeniaminK
Copy link

BeniaminK commented Mar 16, 2022

package com.bendzi.frameworks.jlatexmath;

import org.scilab.forge.jlatexmath.TeXConstants;
import org.scilab.forge.jlatexmath.TeXFormula;
import org.scilab.forge.jlatexmath.TeXIcon;

import javax.swing.*;
import java.awt.*;

public class JLatexMathTesting {

    public static void main(String[] argv) {

        String chineseText = "是次合作為大型科研計劃「大灣區光化學臭氧污染及區域和跨區域傳輸特徵研究」的一部分。該計劃由廣東省政府、香港特區政府和澳門特區政府聯合推出,旨在研究臭氧對整個區域所造成的空氣質素問題。";
        String englishText = "I live in a house near the mountains. I have two brothers and one sister, and I was born last. ";
        
        String englishLongWord = englishText.replaceAll(" ", "");
        
        String koreanText = " 모든 사람은 교육을 받을 권리를 가진다 . 교육은 최소한 초등 및 기초단계에서는 무상이어야 한다. 초등교육은 의무적이어야 한다. 기술 및 직업교육은 일반적으로 접근이 가능하여야 하며, 고등교육은 모든 사람에게 실력에 근거하여 동등하게 접근 가능하여야 한다.";
        
        String koreanLongWord = koreanText.replaceAll(" ", "");

        String[] texts = {
                chineseText,
                englishText,
                englishLongWord,
                koreanText,
                koreanLongWord,

        };

        JFrame jf = new JFrame();

        GridLayout layoutManager = new GridLayout(texts.length, 1);

        JPanel contentPane = new JPanel(layoutManager);
        contentPane.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

        jf.setContentPane(contentPane);

        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        for (String text : texts) {
            TeXFormula formula = new TeXFormula("\\text{ " + text + "}");
            TeXIcon icon = formula.new TeXIconBuilder().setStyle(TeXConstants.STYLE_DISPLAY)
                    .setSize(16)
                    .setWidth(TeXConstants.UNIT_PIXEL, 256f, TeXConstants.ALIGN_CENTER)
                    .setIsMaxWidth(true).setInterLineSpacing(TeXConstants.UNIT_PIXEL, 20f)
                    .build();

            JLabel jl = new JLabel(icon);
            jl.setBorder(BorderFactory.createLineBorder(Color.BLACK));

            contentPane.add(jl);
        }

        jf.pack();
        jf.setVisible(true);
    }

}

Please, refer to this full example. Line breaks is supported by jLatexMath - however it doesn't work on the chinese utf-8 whitespace symbols. Furthermore - in XeLatex, when using the \usepackage{xeCJK} package - it breaks even on word symbols.

@murkle
Copy link
Collaborator

murkle commented Mar 16, 2022

Sorry, not sure what you mean by "chinese utf-8 whitespace symbols" - what is the Unicode number for those?

@murkle
Copy link
Collaborator

murkle commented Mar 16, 2022

@fnatter
Copy link
Contributor

fnatter commented Mar 16, 2022

BTW setIsMaxWidth() isn't present any more in the currently developed version (https://github.com/opencollab/jlatexmath/blob/experimental/jlatexmath/src/main/java/org/scilab/forge/jlatexmath/share/TeXFormula.java )

hello murkle,
thanks for the heads-up!

it looks like we need to set a length in the TeXEnvironment in order to get automatic line breaking:

https://github.com/opencollab/jlatexmath/blob/experimental/jlatexmath/src/main/java/org/scilab/forge/jlatexmath/share/TeXFormula.java#L429

Is experimental the branch leading up to 2.0 or 1.0.8?

Cheers and Best Regards,
Felix

@murkle
Copy link
Collaborator

murkle commented Mar 16, 2022

experimental == v2.0

@BeniaminK
Copy link

Sorry, not sure what you mean by "chinese utf-8 whitespace symbols" - what is the Unicode number for those?

U+3000, U+3001, U+3002, U+300C, U+300D and many many more. I don't think it's even possible to list them all in fact (I'm not that familiar with ideographic characters).

However the solution that breaks the lines at characters might work well too as it would add a line breaks for the cases above too. (maybe as an optional flag)

@murkle
Copy link
Collaborator

murkle commented Mar 16, 2022

I agree that https://www.fileformat.info/info/unicode/char/3000/index.htm is whitespace but not https://www.fileformat.info/info/unicode/char/3001/index.htm - that's a comma

I don't think you'd want to break on https://www.fileformat.info/info/unicode/char/300c/index.htm

You can use Character.isWhitespace() https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html

If that's not what you want then you'll need to compile a full list of what you do want to break on as a first step

@pablogzlezmora
Copy link

Does the JLaTeXMath of GeoGebra have auto linebreak?

@murkle
Copy link
Collaborator

murkle commented May 4, 2022

Nope

@pablogzlezmora
Copy link

Thanks, Michael. :-(

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

5 participants