Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ This version might not be stable, but to install it use::

pip install git+https://github.com/JelteF/PyLaTeX.git

Added
~~~~~
- Add support for the ``\emph`` command

1.4.2_ - `docs <../v1.4.2/>`__ - 2023-10-19
-------------------------------------------

Expand Down
3 changes: 2 additions & 1 deletion examples/full.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Tabular,
TikZ,
)
from pylatex.utils import italic
from pylatex.utils import italic, emphasis

if __name__ == "__main__":
image_filename = os.path.join(os.path.dirname(__file__), "kitten.jpg")
Expand All @@ -38,6 +38,7 @@
with doc.create(Section("The simple stuff")):
doc.append("Some regular text and some")
doc.append(italic("italic text. "))
doc.append(emphasis("Even some emphasized text. "))
doc.append("\nAlso some crazy characters: $&#{}")
with doc.create(Subsection("Math that is incorrect")):
doc.append(Math(data=["2*3", "=", 9]))
Expand Down
30 changes: 30 additions & 0 deletions pylatex/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,36 @@ def italic(s, *, escape=True):
return NoEscape(r"\textit{" + s + "}")


def emphasis(s, *, escape=True):
r"""Make a string appear emphasis in LaTeX formatting.

emphasis() wraps a given string in the LaTeX command \emph{}.

Args
----
s : str
The string to be formatted.
escape: bool
If true the emphasis text will be escaped

Returns
-------
NoEscape
The formatted string.

Examples
--------
>>> emphasis("hello")
NoEscape(\emph{hello})
>>> print(emphasis("hello"))
\emph{hello}
"""
if escape:
s = escape_latex(s)

return NoEscape(r"\emph{" + s + "}")


def verbatim(s, *, delimiter="|"):
r"""Make the string verbatim.

Expand Down
3 changes: 3 additions & 0 deletions tests/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
fix_filename,
italic,
verbatim,
emphasis,
)

matplotlib.use("Agg") # Not to use X server. For TravisCI.
Expand Down Expand Up @@ -493,6 +494,8 @@ def test_utils():

italic(s="")

emphasis(s="")

verbatim(s="", delimiter="|")


Expand Down