TransWikia.com

Highlight environment by setting a violet background color that works on xelatex

TeX - LaTeX Asked by Alex990MW on June 24, 2021

Please, what I need is an example environment that has a violet [rgb(238, 130, 238) for example] background, the font color black and this has to work on xelatex (I need this compiler because I’m working with Japanese texts and furigana that only works on xelatex)

Use this sentence on your example:
usepackage{mathptmx}
begin{document}
begin{example}
{fontsize{25}{30}selectfont 口} meaning mouth
Kun’yomi: くち
On’yomi: コウ、ク
end{example}
end{document}

2 Answers

you can e.g. use tcolorbox. It will works with xelatex too:

documentclass{article}
usepackage{tcolorbox}
definecolor{myviolett}{RGB}{238, 130, 238}
begin{document}
begin{tcolorbox}[colback=myviolett]
some text
end{tcolorbox}
end{document}

enter image description here

Correct answer by Ulrike Fischer on June 24, 2021

The following works in either LuaLaTeX or XeLaTeX:

documentclass{article}
tracinglostchars=2 % Warn if a character is missing
usepackage{iftex} % For ifluatex, ifxetex
usepackage[english]{babel}
usepackage{unicode-math} % For setmathfont
usepackage{xcolor, framed} % For shaded*

defaultfontfeatures{ Scale=MatchLowercase,
                      Ligatures=TeX }

babelfont{rm}
          [Ligatures=Common,Scale=1.0,Language=Default]{TeX Gyre Termes} % Clone of Times.
babelfont{sf}
          [Ligatures=Common,Language=Default]{TeX Gyre Heros} % Clone of Helvetica.
babelfont{tt}
          [Language=Default]{Libertinus Mono}
setmathfont{TeX Gyre Termes Math}

ifluatex
  babelprovide[import, onchar=ids fonts]{japanese}
else
  babelprovide[import]{japanese}
  usepackage{ucharclasses}
  setTransitionsForJapanese%
    {begin{otherlanguage}{japanese}}%
    {end{otherlanguage}}
fi

babelfont[japanese]{rm}
          [Renderer=HarfBuzz]{HaranoAjiMincho}
babelfont[japanese]{sf}
          [Renderer=HarfBuzz]{HaranoAjiGothic}
% Define babelfont[japanese]{tt} here, if needed.

definecolor{shadecolor}{RGB}{238, 130, 238}
newenvironment{example}%
               {begin{shaded*}}%
               {end{shaded*}}

begin{document}
begin{example}
{huge 口} meaning mouth Kun'yomi: くち On'yomi: コウ、ク 
end{example}
end{document}

Termes/Hirano Aji Mincho sample

Here, I used the framed package, which should be able to deal with page breaks. Ulrike Fischer’s solution based on tcolorbox will also work, and you can configure that package to do fancier things.

Answered by Davislor on June 24, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP