Discussion:
[Docutils-users] styling a replacement
Tom Roche
2016-02-28 23:00:32 UTC
Permalink
[footnotes follow .sig]
However I want to combine inline markup and a substitution providing a subscript, for something like the following reST:

fail1> Cities produce more than 70% of global fossil-fuel |CO2| emissions (*|FFCO2|*). We have cutting-edge science relating how cities and regions settle and use their land (LULC) to their |FFCO2| emissions.

fail1> .. |CO2| replace:: CO\ :sub:`2`
fail1> .. |FFCO2| replace:: FFCO\ :sub:`2`

to show (when rendered, e.g., by `restview`) "FFCO2"

* the first time in italic, the second time not
* both times with '2' subscripted
* neither times with the '|' showing

The above fragment fails, as

- only the second "FFCO2" is subscripted
- the first "FFCO2" both shows the pipes and does not subscript

I also tried

fail2> Cities produce more than 70% of global fossil-fuel |CO2| emissions (|iFFCO2|). We have cutting-edge science relating how cities and regions settle and use their land (LULC) to their FFCO2 emissions.

fail2> .. |CO2| replace:: CO\ :sub:`2`
fail2> .. |FFCO2| replace:: FFCO\ :sub:`2`
fail2> .. |iFFCO2| replace:: *|FFCO2|*

which produces identical (failed results). Thanks to FAQ section 2.16[1] I learned I could do the following, which works:

works> Cities produce more than 70% of global fossil-fuel |CO2| emissions (|iFFCO2|). We have cutting-edge science relating how cities and regions settle and use their land (*LULC*) to their |FFCO2| emissions.

works> .. |CO2| replace:: CO\ :sub:`2`
works> .. |FFCO2| replace:: FFCO\ :sub:`2`
works> .. |iFFCO2| raw:: html
works>
works> <em>FFCO<sub>2</sub></em>

but I'd prefer to do this (and similar simple styling of replacements) without `raw` directives. Is that currently possible?

If possible please reply to me (directly) as well as the list, and
TIA, Tom Roche <***@pobox.com>

[1]: http://docutils.sourceforge.net/FAQ.html#is-nested-inline-markup-possible

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
Docutils-users mailing list
Docutils-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/docutils-users

Please use "Reply All" to reply to the list.
David Goodger
2016-02-28 23:19:47 UTC
Permalink
Post by Tom Roche
[footnotes follow .sig]
What you're asking for is nested inline markup via substitution, and
that is not currently possible, no.

Suggestion: rather than a substitution, use the Unicode subscript
characters, e.g. CO₂, FFCO₂, H₂O. Superscripts too: E=mc². These can
be styled with emphasis: *CO₂*, **FFCO₂**, etc. For easy character
entry, explore the "compose key" functionality
(https://en.wikipedia.org/wiki/Compose_key) standard in Linux distros
and easily added to MacOS & Windows systems.

David Goodger
<http://python.net/~goodger>
Post by Tom Roche
fail1> Cities produce more than 70% of global fossil-fuel |CO2| emissions (*|FFCO2|*). We have cutting-edge science relating how cities and regions settle and use their land (LULC) to their |FFCO2| emissions.
fail1> .. |CO2| replace:: CO\ :sub:`2`
fail1> .. |FFCO2| replace:: FFCO\ :sub:`2`
to show (when rendered, e.g., by `restview`) "FFCO2"
* the first time in italic, the second time not
* both times with '2' subscripted
* neither times with the '|' showing
The above fragment fails, as
- only the second "FFCO2" is subscripted
- the first "FFCO2" both shows the pipes and does not subscript
I also tried
fail2> Cities produce more than 70% of global fossil-fuel |CO2| emissions (|iFFCO2|). We have cutting-edge science relating how cities and regions settle and use their land (LULC) to their FFCO2 emissions.
fail2> .. |CO2| replace:: CO\ :sub:`2`
fail2> .. |FFCO2| replace:: FFCO\ :sub:`2`
fail2> .. |iFFCO2| replace:: *|FFCO2|*
works> Cities produce more than 70% of global fossil-fuel |CO2| emissions (|iFFCO2|). We have cutting-edge science relating how cities and regions settle and use their land (*LULC*) to their |FFCO2| emissions.
works> .. |CO2| replace:: CO\ :sub:`2`
works> .. |FFCO2| replace:: FFCO\ :sub:`2`
works> .. |iFFCO2| raw:: html
works>
works> <em>FFCO<sub>2</sub></em>
but I'd prefer to do this (and similar simple styling of replacements) without `raw` directives. Is that currently possible?
If possible please reply to me (directly) as well as the list, and
[1]: http://docutils.sourceforge.net/FAQ.html#is-nested-inline-markup-possible
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
Docutils-users mailing list
Docutils-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/docutils-users

Please use "Reply All" to reply
Tom Roche
2016-02-29 23:29:13 UTC
Permalink
Tom Roche Sun, 28 Feb 2016 16:00:32 -0700
Can one style a non-link replacement (e.g., emphasize text with a subscript) without a `raw` directive?
David Goodger Sun, 28 Feb 2016 17:19:47 -0600
Thanks, I ended up doing that: `restview` rendered my `raw` directive correctly, but the Bitbucket reST renderer currently does not.
For easy character entry,
Like Oleksandr Gavenko in this thread, I use Emacs, so Unicode entry is not usually a problem (though I just use `C-x 8 RET <name/>`).

thanks all, Tom Roche <***@pobox.com>

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
Docutils-users mailing list
Docutils-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/docutils-users

Pleas

Oleksandr Gavenko
2016-02-29 17:23:38 UTC
Permalink
Post by Tom Roche
However I want to combine inline markup and a substitution providing a
fail1> Cities produce more than 70% of global fossil-fuel |CO2| emissions
fail1> (*|FFCO2|*). We have cutting-edge science relating how cities and
fail1> regions settle and use their land (LULC) to their |FFCO2| emissions.
fail1> .. |CO2| replace:: CO\ :sub:`2`
fail1> .. |FFCO2| replace:: FFCO\ :sub:`2`
Recently I take notes for Coursera classes in RST and I like :math:
role/directive rendering:

$ cat in.rst

This is :math:`CO_2`.

$ rst2html --math-output=HTML in.rst out.html

$ cat out.html

<span class="formula"><i>CO</i><sub>2</sub></span>

As you see default rendering enclose text in italic tag - so text will look
emphasised.

You source code will be readable in plain text.

:math: try to interpret included text as TeX formula, so relatively complex
typography can be represented with this syntax.

I don't use much of \LaTeX syntax in flavor of Emacs editor abilities for
easy entering complex text.

With binding:

(setq my-russian-input-method 'russian-computer)
(setq my-ukranian-input-method 'ukrainian-computer)
(setq my-ipa-input-method 'ipa-x-sampa)
(when (<= emacs-major-version 21)
(setq my-russian-input-method 'cyrillic-jcuken)
(setq my-ukranian-input-method 'cyrillic-jcuken))
(setq default-input-method my-russian-input-method)

(defun my-toggle-input-method (&optional arg)
(interactive "P")
(if (numberp arg)
(cond
((eq arg 1)
(activate-input-method nil))
((eq arg 2)
(activate-input-method my-russian-input-method))
((eq arg 3)
(activate-input-method my-ukranian-input-method))
((eq arg 4)
(activate-input-method 'greek))
((eq arg 5)
(activate-input-method my-ipa-input-method))
((eq arg 6)
(activate-input-method 'TeX)) )
(toggle-input-method arg)) )

(global-set-key (kbd "C-\\") 'my-toggle-input-method)

I able to enter Ru/Ua/Greek/IPA/TeX symbols without effort. For:

:def:`Chebyshev inequality`: if :math:`X` is a random variable with mean
:math:`μ` and variance :math:`σ²` then

.. math::

P(|X-μ| ≥ c) ≤ σ²/c²

for all :math:`c > 0`.

with TeX input method when I type [^] [2] Emacs automatically place superscript
number 2. Same for [_] [2] which may be useful in your chemistry text.
[\] [s] [u] [m] produces ∑ sign, there are hundreds of symbols can be entered
in such way.

Note that Unicode doesn't hold all subscript/superscript for English alphabet,
so I use LeTeX syntax which look nice in plain text and HTML:

Z_n = ((∑_{1≤i≤n} X_i) - n·μ) / (σ·sqrt(n))

"1≤i≤n" become subscript in HTML.

If you prefer to use limited editor I may suggest you to make file with list
of interesting Unicode chars and copy-paste them.

I don't like --math-output=MathJax because it link to external CDN and it
really slow in may part of world )) --math-output=HTML just fine.

Recently I found that option in form

--math-output=MathJax:http://you.domain/context/mathjax.js

allow link to your own copy of mathjax library but again built-in
--math-output=HTML just fine.

================================================================

I check:

http://docutils.sourceforge.net/docs/ref/rst/directives.html#custom-interpreted-text-roles

If define:

.. role:: chem(math)
:class: chem

This is :chem:`H_2O`.

you unfortunately get:

<span class="formula"><i>CO</i><sub>2</sub></span>

There are no additional class "chem" but it would be great to have to
customise chemical and mathematical formulas.

I file a bug:

https://sourceforge.net/p/docutils/bugs/295/
#295 Custom text role with inheritence on math role should respect additional class
--
http://defun.work/


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
Docutils-users mailing list
Docutils-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/docutils-users

Pleas
Loading...