Repository: ipython/ipython

Issue:
under Windows, "ipython3 nbconvert "C:/blabla/first_try.ipynb" --to latex" write "\" instead of "/" to reference file path in the .tex file
Hello,

I tried the new nbconvert feature of IPython1.0.0rc1  this morning on a Windows Vista PC. 
The .TEX generated file is perfect EXCEPT the directory separator character, which is unfortunately written as "\" instead of "/".

Example (abstract) :
***\* instruction used to create the .TEX file ****
ipython3 nbconvert "C:/blabla/bla/first_try.ipynb" --to latex 

gives (First 5 lines) : 
***_(begining of abstract) ***_*
% Header, overrides base
    % Make sure that the sphinx doc style knows who it inherits from.
    \def\sphinxdocclass{article}
    % Declare the document class
    \documentclass[letterpaper,10pt,english]{C:\blabla\winpython\WinPython-32bit-3.3.2.1rc1\python-3.3.2\lib\site-packages\sphinx\texinputs/sphinxhowto}
**\* (..., then a reference to another document, also with a "\" instead of a "/") ***
\begin{center}
    \includegraphics[max size={\textwidth}{\textheight}]{first_try_files\first_try_3_0.png}
    \par
    \end{center}
**\* (end of abstract) *****



Discussion:

Resolving patch:
diff --git a/IPython/nbconvert/exporters/exporter.py b/IPython/nbconvert/exporters/exporter.py
--- a/IPython/nbconvert/exporters/exporter.py
+++ b/IPython/nbconvert/exporters/exporter.py
@@ -55,6 +55,7 @@
         'highlight2html': filters.highlight2html,
         'highlight2latex': filters.highlight2latex,
         'ipython2python': filters.ipython2python,
+        'posix_path': filters.posix_path,
         'markdown2latex': filters.markdown2latex,
         'markdown2rst': filters.markdown2rst,
         'comment_lines': filters.comment_lines,
@@ -66,7 +67,7 @@
         'ansi2latex': filters.ansi2latex,
         'strip_math_space': filters.strip_math_space,
         'wrap_text': filters.wrap_text,
-        'escape_latex': filters.escape_latex
+        'escape_latex': filters.escape_latex,
 }
 
 #-----------------------------------------------------------------------------
diff --git a/IPython/nbconvert/filters/strings.py b/IPython/nbconvert/filters/strings.py
--- a/IPython/nbconvert/filters/strings.py
+++ b/IPython/nbconvert/filters/strings.py
@@ -16,6 +16,7 @@
 # Imports
 #-----------------------------------------------------------------------------
 
+import os
 import re
 import textwrap
 from xml.etree import ElementTree
@@ -36,6 +37,7 @@
     'comment_lines',
     'get_lines',
     'ipython2python',
+    'posix_path',
 ]
 
 
@@ -169,3 +171,13 @@ def ipython2python(code):
     """
     shell = InteractiveShell.instance()
     return shell.input_transformer_manager.transform_cell(code)
+
+def posix_path(path):
+    """Turn a path into posix-style path/to/etc
+    
+    Mainly for use in latex on Windows,
+    where native Windows paths are not allowed.
+    """
+    if os.path.sep != '/':
+        return path.replace(os.path.sep, '/')
+    return path


Test patch:
diff --git a/IPython/nbconvert/filters/tests/test_strings.py b/IPython/nbconvert/filters/tests/test_strings.py
--- a/IPython/nbconvert/filters/tests/test_strings.py
+++ b/IPython/nbconvert/filters/tests/test_strings.py
@@ -13,11 +13,13 @@
 #-----------------------------------------------------------------------------
 # Imports
 #-----------------------------------------------------------------------------
+import os
 
 from IPython.testing import decorators as dec
 from ...tests.base import TestsBase
 from ..strings import (wrap_text, html2text, add_anchor, strip_dollars, 
-    strip_files_prefix, get_lines, comment_lines, ipython2python)
+    strip_files_prefix, get_lines, comment_lines, ipython2python, posix_path,
+)
 
 
 #-----------------------------------------------------------------------------
@@ -117,3 +119,10 @@ def test_ipython2python(self):
         results = ipython2python(u'%%pylab\nprint("Hello-World")').replace("u'", "'")
         self.fuzzy_compare(results, u"get_ipython().run_cell_magic('pylab', '', 'print(\"Hello-World\")')", 
             ignore_spaces=True, ignore_newlines=True)
+    
+    def test_posix_path(self):
+        path_list = ['foo', 'bar']
+        expected = '/'.join(path_list)
+        native = os.path.join(*path_list)
+        filtered = posix_path(native)
+        self.assertEqual(filtered, expected)