Text FormattingFull justify with greek text

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
bstex
Posts: 69
Joined: Mon Oct 23, 2017 10:22 am

Full justify with greek text

Post by bstex »

Hi.
Does anyone know why this is happening with the justify on my Greek text? Some letters are going OUT of the justify line. It doesn't happen when I type English text.
Maybe hyphenation is a solution, but I would like not to use hyphenation on Greek text.
justify.png
justify.png (57.25 KiB) Viewed 5795 times
Thank you in advance.

P.S. The text on the image contains understandable Greek words. Don't try to understand them. :)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Full justify with greek text

Post by Stefan Kottwitz »

Hi,

it looks like hyphenation is disabled. This could be a property of the font. And you may need to load the right font encoding. Loading the microtype package may help too.

Can you post a small compilable code with the document settings in your preamble (same font settings, same page width etc.) with that text as sample, so we can test a fix? If the text contains some information, you don't want to see online, we can remove the text after the problem is solved.

Stefan
LaTeX.org admin
bstex
Posts: 69
Joined: Mon Oct 23, 2017 10:22 am

Full justify with greek text

Post by bstex »

Hi,
I changed my main font to "Times New Roman" and I have the same problem, so I don't think that the problem is the "Myriad Pro" font that I use.

My "structure.tex" file contains this code:

Code: Select all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The Legrand Orange Book
% Structural Definitions File
% Version 2.0 (9/2/15)
%
% Original author:
% Mathias Legrand (legrand.mathias@gmail.com) with modifications by:
% Vel (vel@latextemplates.com)
% 
% This file has been downloaded from:
% http://www.LaTeXTemplates.com
%
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%----------------------------------------------------------------------------------------
%	VARIOUS REQUIRED PACKAGES AND CONFIGURATIONS
%----------------------------------------------------------------------------------------
\usepackage[table]{xcolor}

\usepackage[top=2.5cm,bottom=2.5cm,inner=3cm,outer=2cm,headsep=10pt,a4paper]{geometry} % Page margins

\linespread{1.1}

\usepackage{graphicx} % Required for including pictures
\graphicspath{{Pictures/}} % Specifies the directory where pictures are stored

\usepackage{lipsum} % Inserts dummy text

\usepackage{tikz} % Required for drawing custom shapes

\usepackage[english]{babel} % English language/hyphenation

\usepackage{enumitem} % Customize lists
\setlist{nolistsep} % Reduce spacing between bullet points and numbered lists

\usepackage{booktabs} % Required for nicer horizontal rules in tables

\usepackage{xcolor} % Required for specifying colors by name
\definecolor{ocre}{RGB}{243,102,25} % Define the orange color used for highlighting throughout the book

\usepackage{array}

\usepackage[version=4]{mhchem}

\usepackage{tcolorbox}

\usepackage[version=4]{mhchem}
\mhchemoptions{textfontcommand=\sffamily}
\mhchemoptions{mathfontcommand=\mathsf}

\usetikzlibrary{positioning,shapes.callouts}

%----------------------------------------------------------------------------------------
%	FONTS
%----------------------------------------------------------------------------------------

\usepackage{avant} % Use the Avantgarde font for headings
\usepackage{times} % Use the Times font for headings
\usepackage{mathptmx} % Use the Adobe Times Roman as the default text font together with math symbols from the Sym­bol, Chancery and Com­puter Modern fonts

\usepackage{microtype} % Slightly tweak font spacing for aesthetics
\usepackage[utf8]{inputenc} % Required for including letters with accents
\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs

\usepackage{fontspec}

\usepackage{titlesec}
\defaultfontfeatures{Ligatures=TeX}
\setsansfont{Times New Roman}
\setmainfont{Myriad Pro}

%----------------------------------------------------------------------------------------
%	BIBLIOGRAPHY AND INDEX
%----------------------------------------------------------------------------------------

\usepackage[style=numeric,citestyle=numeric,sorting=nyt,sortcites=true,autopunct=true,babel=hyphen,hyperref=true,abbreviate=false,backref=true,backend=biber]{biblatex}
\addbibresource{bibliography.bib} % BibTeX bibliography file
\defbibheading{bibempty}{}

\usepackage{calc} % For simpler calculation - used for spacing the index letter headings correctly
\usepackage{makeidx} % Required to make an index
\makeindex % Tells LaTeX to create the files required for indexing


%----------------------------------------------------------------------------------------
%	THEOREM STYLES
%----------------------------------------------------------------------------------------

\usepackage{amsmath,amsfonts,amssymb,amsthm} % For math equations, theorems, symbols, etc

\newcommand{\intoo}[2]{\mathopen{]}#1\,;#2\mathclose{[}}
\newcommand{\ud}{\mathop{\mathrm{{}d}}\mathopen{}}
\newcommand{\intff}[2]{\mathopen{[}#1\,;#2\mathclose{]}}
\newtheorem{notation}{Notation}[chapter]

% Boxed/framed environments
\newtheoremstyle{ocrenumbox}% % Theorem style name
{0pt}% Space above
{0pt}% Space below
{\normalfont}% % Body font
{}% Indent amount
{\small\bf\sffamily\color{ocre}}% % Theorem head font
{\;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{\large\sffamily\color{lightblue4}\thmname{#1}\nobreakspace\thmnumber{\@ifnotempty{#1}{}\@upn{#2}}% Theorem text (e.g. Theorem 2.1)
\thmnote{\nobreakspace\the\thm@notefont\sffamily\bfseries\color{black}---\nobreakspace#3.}} % Optional theorem note
\renewcommand{\qedsymbol}{$\blacksquare$}% Optional qed square

\newtheoremstyle{blacknumex}% Theorem style name
{5pt}% Space above
{5pt}% Space below
{\normalfont}% Body font
{} % Indent amount
{\small\bf\sffamily}% Theorem head font
{\;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{\small\sffamily{\tiny\ensuremath{\blacksquare}}\nobreakspace\thmname{#1}\nobreakspace\thmnumber{\@ifnotempty{#1}{}\@upn{#2}}% Theorem text (e.g. Theorem 2.1)
\thmnote{\nobreakspace\the\thm@notefont\sffamily\bfseries---\nobreakspace#3.}}% Optional theorem note

\newtheoremstyle{blacknumbox} % Theorem style name
{0pt}% Space above
{0pt}% Space below
{\normalfont}% Body font
{}% Indent amount
{\small\bf\sffamily}% Theorem head font
{\;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{\small\sffamily\thmname{#1}\nobreakspace\thmnumber{\@ifnotempty{#1}{}\@upn{#2}}% Theorem text (e.g. Theorem 2.1)
\thmnote{\nobreakspace\the\thm@notefont\sffamily\bfseries---\nobreakspace#3.}}% Optional theorem note

% Non-boxed/non-framed environments
\newtheoremstyle{ocrenum}% % Theorem style name
{5pt}% Space above
{5pt}% Space below
{\normalfont}% % Body font
{}% Indent amount
{\small\bf\sffamily\color{ocre}}% % Theorem head font
{\;}% Punctuation after theorem head
{0.25em}% Space after theorem head
{\small\sffamily\color{ocre}\thmname{#1}\nobreakspace\thmnumber{\@ifnotempty{#1}{}\@upn{#2}}% Theorem text (e.g. Theorem 2.1)
\thmnote{\nobreakspace\the\thm@notefont\sffamily\bfseries\color{black}---\nobreakspace#3.}} % Optional theorem note
\renewcommand{\qedsymbol}{$\blacksquare$}% Optional qed square
\makeatother

% Defines the theorem text style for each type of theorem to one of the three styles above
\newcounter{dummy} 
\numberwithin{dummy}{section}
\theoremstyle{ocrenumbox}
\newtheorem{theoremeT}[dummy]{Theorem}
\newtheorem{problem}{Problem}[chapter]
\newtheorem{exerciseT}{}[chapter]
\theoremstyle{blacknumex}
\newtheorem{exampleT}{Example}[chapter]
\theoremstyle{blacknumbox}
\newtheorem{vocabulary}{Vocabulary}[chapter]
\newtheorem{definitionT}{Definition}[section]
\newtheorem{corollaryT}[dummy]{Corollary}
\theoremstyle{ocrenum}
\newtheorem{proposition}[dummy]{Proposition}

%----------------------------------------------------------------------------------------
%	DEFINITION OF COLORED BOXES
%----------------------------------------------------------------------------------------

\RequirePackage[framemethod=default]{mdframed} % Required for creating the theorem, definition, exercise and corollary boxes

% Theorem box
\newmdenv[skipabove=7pt,
skipbelow=7pt,
backgroundcolor=black!5,
linecolor=ocre,
innerleftmargin=5pt,
innerrightmargin=5pt,
innertopmargin=5pt,
leftmargin=0cm,
rightmargin=0cm,
innerbottommargin=5pt]{tBox}

% Exercise box	  
\newmdenv[skipabove=7pt,
skipbelow=7pt,
rightline=false,
leftline=true,
topline=false,
bottomline=false,
%backgroundcolor=lightblue4!10,
%linecolor=lightblue4,
innerleftmargin=5pt,
innerrightmargin=5pt,
innertopmargin=5pt,
innerbottommargin=5pt,
leftmargin=0cm,
rightmargin=0cm,
linewidth=0pt]{eBox}	% Ήταν linewidth=4pt]{eBox}	

% Definition box
\newmdenv[skipabove=7pt,
skipbelow=7pt,
rightline=false,
leftline=true,
topline=false,
bottomline=false,
linecolor=ocre,
innerleftmargin=5pt,
innerrightmargin=5pt,
innertopmargin=0pt,
leftmargin=0cm,
rightmargin=0cm,
linewidth=4pt,
innerbottommargin=0pt]{dBox}	

% Corollary box
\newmdenv[skipabove=7pt,
skipbelow=7pt,
rightline=false,
leftline=true,
topline=false,
bottomline=false,
linecolor=gray,
backgroundcolor=black!5,
innerleftmargin=5pt,
innerrightmargin=5pt,
innertopmargin=5pt,
leftmargin=0cm,
rightmargin=0cm,
linewidth=4pt,
innerbottommargin=5pt]{cBox}

% Creates an environment for each type of theorem and assigns it a theorem text style from the "Theorem Styles" section above and a colored box from above
\newenvironment{theorem}{\begin{tBox}\begin{theoremeT}}{\end{theoremeT}\end{tBox}}
\newenvironment{exercise}{\begin{eBox}\begin{exerciseT}}{\end{exerciseT}\end{eBox}}

\newenvironment{definition}{\begin{dBox}\begin{definitionT}}{\end{definitionT}\end{dBox}}	
\newenvironment{example}{\begin{exampleT}}{\hfill{\tiny\ensuremath{\blacksquare}}\end{exampleT}}		
\newenvironment{corollary}{\begin{cBox}\begin{corollaryT}}{\end{corollaryT}\end{cBox}}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Full justify with greek text

Post by Stefan Kottwitz »

The Greek font is Times New Roman or Myriad Pro? Sure that it's not another font and Times or Myriad Pro is used for English?

Just seeing the structure.tex doesn't let me reproduce and test the problem. No greek text here.

Stefan
LaTeX.org admin
bstex
Posts: 69
Joined: Mon Oct 23, 2017 10:22 am

Full justify with greek text

Post by bstex »

Hope this helps now:

Code: Select all

\documentclass[12pt,a4paper,fleqn]{book} % Default font size and left-justified equations

\input{structure} % Insert the commands.tex file which contains the majority of the structure behind the template

\begin{document}

\chapter{Chatper 1}

\section*{Example 1}\index{Paragraphs of Text}

\section*{Exercises}\index{Exercises}

\begin{exercise}
Λορεμ ιπσθμ δολορ σιτ αμετ, θσθ εξ μινιμ ιμπετθσ cομπλεcτιτθρ, θτ vιξ νοvθμ ιγνοτα αργθμεντθμ. Ετ ηισ νθλλαμ φορενσιβθσ. Vισ ετ σολθμ ηαβεμθσ σιμιλιqθε, ασσθμ μθcιθσ γραεcι ηισ ει. Ορνατθσ μεντιτθμ εθμ θτ. Ενιμ απειριαν περσεcθτι ει σιτ, ει εοσ ηινc νομινατι cονcεπταμ.Cθ μθτατ γραεcισ δελιcατα μει, μθνδι ριδενσ ρεcθσαβο νε ναμ. Νο cιvιβθσ σcριπιτ ηισ. Τε ιθσ παθλο τινcιδθντ αππελλαντθρ, φεθγαιτ ρατιονιβθσ vιμ ιν. Ιν περ jθστο cηορο λεγενδοσ, οδιο vιταε μενανδρι μελ νε. Οπορτεατ σενσιβθσ πρινcιπεσ νο πρι, ριδενσ νεγλεγεντθρ τε vιξ. Σεδ ατ αεqθε ελιγενδι δισσεντιασ. Μελ νο αμετ πθτεντ. Ορνατθσ μεντιτθμ εθμ θτ. Ενιμ απειριαν περσεcθτι ει σιτ, ει εοσ ηινc νομινατι cονcεπταμ.Cθ μθτατ γραεcισ δελιcατα μει, μθνδι ριδενσ ρεcθσαβο νε ναμ.

\end{exercise}

\end{document}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Full justify with greek text

Post by Stefan Kottwitz »

No, it doesn't. Did you test it?
Please test your code and ensure that it shows Greek and the problem. Even if I fix it (defining ocre color because of an error...) I get this:
no-greek.png
no-greek.png (12.96 KiB) Viewed 5753 times
Stefan
LaTeX.org admin
bstex
Posts: 69
Joined: Mon Oct 23, 2017 10:22 am

Full justify with greek text

Post by bstex »

Yes, my .pdf file shows greek text correctly. Maybe you don't have the "Myriad Pro" font on your computer. :?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Full justify with greek text

Post by Stefan Kottwitz »

Ok, it took another structure.tex from the template. Now I copied in yours. You could make working on it easier by post in self-contained examples, that just need to be compiled, instead of posting several snippets to be combined, and I still had to fix errors before testing (lightblue4 undefined, xcolor option clash).

Using polyglossia helps:

Code: Select all

\usepackage{polyglossia} 
\setotherlanguage{greek}
\setmainlanguage{english} 
...
\begin{exercise}
\foreignlanguage{greek}{Λορεμ ιπσθμ ...}
\end{exercise}
Stefan
LaTeX.org admin
bstex
Posts: 69
Joined: Mon Oct 23, 2017 10:22 am

Full justify with greek text

Post by bstex »

I'm really sorry for the inconvenience. I just removed some text that I thought wasn't necessary...
Well, I have mixed text (english and greek) on my book, even in the same sentences.
So, polyglossia will not be so useful for me. :cry:
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Full justify with greek text

Post by Stefan Kottwitz »

But this works, just use \foreignlanguage{greek}{...} to switch to greek and otherwise use English. No problem mixing it. You can also define yourself a macro with shorter name, for easier typing.

Code: Select all

\newcommand{\gr}[1]{\foreignlanguage{greek}{#1}}

... english text \gr{Λορεμ ιπσθμ...} more english text ...
Stefan
LaTeX.org admin
Post Reply