TransWikia.com

How to add aditional actions to argument into environement

TeX - LaTeX Asked on February 7, 2021

I am starting in LaTeX. I want to write a document and define some styles.

In this case I want to do two things with one portion of a paragraph:

  1. That it has a red color
  2. That it is aligned to the right

My problem is that I don’t know how to do both when defining the environment.

This is my code:

%Define color
newcommand{txtred}[1]{textcolor{red}{#1}}

%Command to use in the context
newcommand{atright}[1]{renewcommand{atright}{#1}}

newenvironment{txtbook}
    {begin{flushleft}}
        {txtred{atright}
    end{flushleft}
}

In the context:

begin{txtbook}Del libro del Génesis hfill atright{9, 8-15}end{txtbook}

This works, but I want to translate hfill to the environment, but I don’t know how to do it.

I am using memoir, if there is some simpler way to do what I want I would appreciate it.

There is one example, at right, there is the argument:

enter image description here

2 Answers

I'd use a command, rather than an environment.

documentclass{memoir}
usepackage{xcolor}

usepackage{lipsum} % for mock text

newcommand{txtbook}[2]{%
  paraddvspace{topsep}
  {centering #1hfilltextcolor{red}{#2}par}nopagebreak
  addvspace{topsep}
}

begin{document}

txtbook{Del libro del Génesis}{9, 8-15}

lipsum[1]

end{document}

enter image description here

Answered by egreg on February 7, 2021

If you really wish to use an environment and your current interface, the following will suffice:

enter image description here

documentclass{memoir}

usepackage{xcolor,lipsum}

newcommand{txtred}{textcolor{red}}
newcommand{atright}{mbox{}hfilltxtred}
newenvironment{txtbook}{%
  raggedright
}{%
  unskippar
}

begin{document}

lipsum[1]

begin{txtbook}
  Del libro del Génesis atright{9, 8-15}
end{txtbook}

lipsum[2]

end{document}

One can add some spacing adjustments, if needed.

Answered by Werner on February 7, 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