0

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}

1
  • As of 2020, the font will also work in LuaLaTeX, which has fewer color bugs.
    – Davislor
    Dec 24, 2020 at 23:21

2 Answers 2

2

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

4
  • Thank you, for this comment, especially for this quick answer at this time of the year. This will work, but I expecting something more sophisticated for a book example, like @Jonathan Komar's answer on tex.stackexchange.com/questions/21227/example-environment ... but the package "mdframed" always results in an error on xelatex. I'll use this in my article's texts now! Thank you, hombre!
    – amuniz1
    Dec 24, 2020 at 23:50
  • @Alex990MW Ulrike is a mujer. :)
    – Davislor
    Dec 25, 2020 at 0:00
  • Sorry, perdão, gomenasai! @Ulrike Fischer
    – amuniz1
    Dec 25, 2020 at 0:05
  • You only asked about violett background and black text, if you want something more sophisticated you should be more specific. Beside this: everything that you can do with mdframed is also possible with tcolorbox (and more, as it is a much more powerful package). Dec 25, 2020 at 11:27
1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .