diff --git a/converters/latex.py b/converters/latex.py index 372861f..d5bdb4a 100755 --- a/converters/latex.py +++ b/converters/latex.py @@ -40,7 +40,7 @@ class ConverterLaTeX(Converter): 5: r'\subparagraph', 6: r'\subparagraph'} user_preamble = None - exclude_cells = None + exclude_cells = [] def in_env(self, environment, lines): """Return list of environment lines for input lines @@ -107,14 +107,19 @@ class ConverterLaTeX(Converter): # Cell codes first carry input code, we use lstlisting for that lines = [ur'\begin{codecell}'] - - lines.extend(self.in_env('codeinput', - self.in_env('lstlisting', cell.input))) + + if 'source' not in self.exclude_cells: + lines.extend(self.in_env('codeinput', + self.in_env('lstlisting', cell.input))) + else: + # Empty output is still needed for LaTeX formatting + lines.extend(self.in_env('codeinput', '')) outlines = [] - for output in cell.outputs: - conv_fn = self.dispatch(output.output_type) - outlines.extend(conv_fn(output)) + if 'output' not in self.exclude_cells: + for output in cell.outputs: + conv_fn = self.dispatch(output.output_type) + outlines.extend(conv_fn(output)) # And then output of many possible types; use a frame for all of it. if outlines: diff --git a/nbconvert.py b/nbconvert.py index ba051d7..5bf6162 100755 --- a/nbconvert.py +++ b/nbconvert.py @@ -75,7 +75,11 @@ if __name__ == '__main__': known_formats) parser.add_argument('-p', '--preamble', help='Path to a user-specified preamble file') - parser.add_argument('-e', '--exclude', help='Comma-separated list of cells to exclude') + parser.add_argument('-e', '--exclude', default='', + help='Comma-separated list of cells to exclude') + args = parser.parse_args() + exclude_cells = [s.strip() for s in args.exclude.split(',')] + main(infile=args.infile[0], format=args.format, - preamble=args.preamble, exclude=args.exclude) + preamble=args.preamble, exclude=exclude_cells)