Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #86795

Re: rst and pypandoc

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'languages.': 0.04; '(except': 0.07; '*not*': 0.07; 'source.': 0.07; 'string': 0.09; 'combines': 0.09; 'escape': 0.09; 'fixed,': 0.09; 'literal': 0.09; 'skip:\\ 10': 0.09; 'python': 0.11; 'mostly': 0.14; '"b"': 0.16; 'arbitrary.': 0.16; 'backslash': 0.16; 'backslash,': 0.16; 'backslashes': 0.16; 'be:': 0.16; 'character.': 0.16; 'hardcoded': 0.16; 'literal,': 0.16; 'mode,': 0.16; 'newlines': 0.16; 'skip:\\ 30': 0.16; 'special.': 0.16; 'string:': 0.16; 'stuff.': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'rules': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'either.': 0.24; 'string,': 0.24; '(or': 0.24; 'header:In-Reply-To:1': 0.27; 'character': 0.29; 'code': 0.31; 'getting': 0.31; 'usually': 0.31; '>>>>': 0.31; 'object.': 0.31; 'file': 0.32; 'compatible': 0.32; 'regular': 0.32; 'quite': 0.32; 'raw': 0.33; 'there,': 0.34; 'could': 0.34; 'but': 0.35; 'should': 0.36; 'two': 0.37; 'same.': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'anything': 0.39; 'explain': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'skip:p 20': 0.39; 'even': 0.60; 'read': 0.60; 'dave': 0.60; 'places': 0.64; 'different': 0.65; 'charset:windows-1252': 0.65; 'reads': 0.68; 'received:74.208': 0.68; 'results': 0.69; 'special': 0.74; 'angel': 0.91; 'same,': 0.91
Date Mon, 02 Mar 2015 18:23:05 -0500
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0
MIME-Version 1.0
To python-list@python.org
Subject Re: rst and pypandoc
References <cliji5FvctU1@mid.individual.net> <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> <clj866F68tpU1@mid.individual.net> <mailman.39.1425305311.13471.python-list@python.org> <clk777Feal8U3@mid.individual.net>
In-Reply-To <clk777Feal8U3@mid.individual.net>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:6LZ1yrdiBTDZuNDUgl1rTqmTvC3QfUu+iXGvZzPDYFC 7tBjmhPMqzLvzpfn7bYke9MaE/wtuMu3uR+1rRacWMKO/tmlcm wbUfqhx7v7cfQwfY3p0gk7nxxYy0EKF+PFtCsYXjAzNo2MuONL IQaVKtIkaV1WBjQPTEvKN3aPnQv6GSCDOOvHl7Tap8WK21dvnh 96+UAr0LElwzpnDie9NGY6vvDcV+fPhOuQuReJdcPW+3UzeobQ 3CqgEWc2uCUKIFfuGrKz2FcTmHL7YS6WoAB9wfJXXlGXjBMHGa h52HGa9y97NMg2fUVDOdDF39gWlUgzgRvlyWim7lYUn6jBOp2q vsuohy4DlbBzfoVv+0h4=
X-UI-Out-Filterresults notjunk:1;
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.19
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.71.1425339347.13471.python-list@python.org> (permalink)
Lines 65
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1425339347 news.xs4all.nl 2941 [2001:888:2000:d::a6]:57084
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:86795

Show key headers only | View raw


On 03/02/2015 05:40 PM, alb wrote:
> Hi Dave,
>
> Dave Angel <davea@davea.name> wrote:
> []
>>>> or use a raw string:
>>>>
>>>> i = r'\\ref{fig:abc}'
>>
>> Actually that'd be:
>>     i = r'\ref{fig:abc}'
>
> Could you explain why I then see the following difference:
>
> In [56]: inp = r'\\ref{fig:abc}'

print inp
    and you should get
      \\ref{fig:abc}

>
> In [57]: print pypandoc.convert(inp, 'latex', format='rst')
> \textbackslash{}ref\{fig:abc\}
>
>
> In [58]: inp = r'\ref{fig:abc}'

print inp
     and you should get
        \ref{fig:abc}

This is NOT the same.

The rules are not arbitrary.  They're quite necessary, and it's the same 
for lots of different languages.  When in a regular literal, the 
backslash is an escape character that combines with the following 
character.  When in a raw literal, the backslash is a backslash, unless 
it's at the end of the string, in which case it's not the end of the 
string, it's an escaped quotation.  (Or something.  Just don't use 
*trailing* backslash in a raw literal)

>
> In [59]: print pypandoc.convert(inp, 'latex', format='rst')
> ref\{fig:abc\}
>
> The two results are clearly *not* the same, even though the two inp
> /claim/ to be the same...
>

When I said backslashes are not special in data read from a file, I 
should also say neither are quotes, or tabs, or anything else.  Python 
just reads them in, and stuffs them into a string object.  Newlines are 
special if you use readline(), but if you use read(), they're not 
special either (except on MSDOS compatible variants, which use two bytes 
for newline.  Even there, if you read a file in "b" mode, they're not 
special either.

So your code is going to mostly be getting strings from files, or from 
calculations, and these backslashes won't be special.  It's only in 
*testing* that you usually deal with this literal stuff.  Or in places 
where the data is fixed, and hardcoded in the source.


-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

rst and pypandoc al.basili@gmail.com (alb) - 2015-03-02 07:59 +0000
  Re: rst and pypandoc Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2015-03-02 12:03 +0100
  Re: rst and pypandoc Dave Angel <davea@davea.name> - 2015-03-02 07:03 -0500
    Re: rst and pypandoc al.basili@gmail.com (alb) - 2015-03-02 12:36 +0000
  Re: rst and pypandoc Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-02 23:33 +1100
    Re: rst and pypandoc al.basili@gmail.com (alb) - 2015-03-02 13:51 +0000
      Re: rst and pypandoc Dave Angel <davea@davea.name> - 2015-03-02 09:08 -0500
        Re: rst and pypandoc Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-03 01:43 +1100
          Re: rst and pypandoc Dave Angel <davea@davea.name> - 2015-03-02 13:55 -0500
          Re: rst and pypandoc Ben Finney <ben+python@benfinney.id.au> - 2015-03-03 06:09 +1100
          Re: rst and pypandoc Dave Angel <davea@davea.name> - 2015-03-02 14:16 -0500
        Re: rst and pypandoc al.basili@gmail.com (alb) - 2015-03-02 22:30 +0000
          Re: rst and pypandoc Chris Angelico <rosuav@gmail.com> - 2015-03-03 09:51 +1100
          Re: rst and pypandoc Ben Finney <ben+python@benfinney.id.au> - 2015-03-03 10:18 +1100
          Re: rst and pypandoc Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-03 10:32 +1100
            Re: rst and pypandoc al.basili@gmail.com (alb) - 2015-03-03 20:35 +0000
        Re: rst and pypandoc al.basili@gmail.com (alb) - 2015-03-02 22:40 +0000
          Re: rst and pypandoc Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-02 23:08 +0000
            Re: rst and pypandoc al.basili@gmail.com (alb) - 2015-03-03 20:37 +0000
          Re: rst and pypandoc Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-03 10:22 +1100
            Re: rst and pypandoc al.basili@gmail.com (alb) - 2015-03-03 20:46 +0000
          Re: rst and pypandoc Dave Angel <davea@davea.name> - 2015-03-02 18:23 -0500
      Re: rst and pypandoc MRAB <python@mrabarnett.plus.com> - 2015-03-02 14:37 +0000
        Re: rst and pypandoc al.basili@gmail.com (alb) - 2015-03-02 22:37 +0000
          Re: rst and pypandoc Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-03-03 19:40 +1300
            Re: rst and pypandoc al.basili@gmail.com (alb) - 2015-03-03 20:50 +0000
              Re: rst and pypandoc Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-03-04 11:27 +1300
      Re: rst and pypandoc MRAB <python@mrabarnett.plus.com> - 2015-03-02 14:40 +0000
      Re: rst and pypandoc Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-03 02:09 +1100

csiph-web