2

I have a long list. It is result obtained from running a python script. It is as follows

[[0, [[38], [65]]]
[0, [[39], [6]]]
[0, [[40], [67]]]
[0, [[41], [68]]]
[0, [[42], [69]]]
[1, [[43], [70]]]
[1, [[44], [71]]]
[0, [[50], [77]]]
[0, [[51], [78]]]
[0, [[52], [79]]]
[1, [[53], [80]]]
[0, [[12], [54]]]
[1, [[13], [55]]]
[1, [[14], [56]]]
[0, [[57]]]
[1, [[58]]]
[0, [[59]]]
[0, [[60]]]
[0, [[61]]]
[1, [[1, 2], [69]]]
[0, [[1], [2, 3], [70]]]
[1, [[2], [3, 4], [71]]]
[1, [[3], [4, 5], [15], [72]]]
[1, [[4], [5, 6], [16], [73]]]
[0, [[5], [6, 7], [17], [74]]]]

I am new to latex and I want to write these in a thesis as part of a result. Splitting the page does not give me desirable results as for other examples the elements get even longer and goes out of view.
Is there a dynamic technique which I can use to add such type of lists efficiently, i.e. the short elements in the same line and longer ones on the next line, without doing it for each case?
Also open for any other suggestions on how to incorporate such list.

  • 1
    Can't you influence the output of the script to meet the requirements of LaTeX? To be honest, I don't understand what you want to achieve from the current form of the question. Maybe you can add a visualization of the desired output. – Dr. Manuel Kuehner Jul 22 '17 at 0:54
  • And what about the missing ] that David asked about? Is it missing or is it on purpose? – Dr. Manuel Kuehner Jul 22 '17 at 0:56
3

there appeared to be a missing ] at the end?

this allows linebreaking after ] that are not nested more than one level.

enter image description here

The above is made with the document at the end, perhaps after comments you meant output like this

enter image description here

with a forced linebreak at top level entries and allowing line breaks in (unshown) longer entries, in which case you need

\begin{flushleft}
\rightskip0pt
\catcode`\[=13
\catcode`\]=13
\def[{\advance\bdepth1 \ifnum\bdepth=2 \hfill\mbox{}\linebreak\fi\lbrack}
\def]{\ifnum\bdepth=1 \hfill\mbox{}\linebreak\fi\rbrack\advance\bdepth-1 
   \ifnum\bdepth=2\penalty-900 \fi\ignorespaces}
$

Original document:

\documentclass{article}
\newcount\bdepth
\errorcontextlines1000
\begin{document}
\begin{flushleft}
\catcode`\[=13
\catcode`\]=13
\def[{\advance\bdepth1 \lbrack}
\def]{\rbrack\advance\bdepth-1 
\ifnum\bdepth<2 \penalty0 \;\fi}
$
[[0, [[38], [65]]]
[0, [[39], [6]]]
[0, [[40], [67]]]
[0, [[41], [68]]]
[0, [[42], [69]]]
[1, [[43], [70]]]
[1, [[44], [71]]]
[0, [[50], [77]]]
[0, [[51], [78]]]
[0, [[52], [79]]]
[1, [[53], [80]]]
[0, [[12], [54]]]
[1, [[13], [55]]]
[1, [[14], [56]]]
[0, [[57]]]
[1, [[58]]]
[0, [[59]]]
[0, [[60]]]
[0, [[61]]]
[1, [[1, 2], [69]]]
[0, [[1], [2, 3], [70]]]
[1, [[2], [3, 4], [71]]]
[1, [[3], [4, 5], [15], [72]]]
[1, [[4], [5, 6], [16], [73]]]
[0, [[5], [6, 7], [17], [74]]]
]%missing?
$
\end{flushleft}

\end{document}
  • This still does not help. The output of the mentioned script still outputs these arrays clumsily. Actually these equations are representation of boolean equations and I want to print them separately – Anmol Yadav Jul 22 '17 at 0:38
  • +1 Didn't think that this could be done in such little code without LuaTex :) – Dr. Manuel Kuehner Jul 22 '17 at 1:00
  • @Dr.ManuelKuehner: David is the author ofxii.tex...By comparison, this is straight forward :-) – Aditya Jul 22 '17 at 1:40
  • 2
    @AnmolYadav you gave no indication of the intended output and your example input was (I assume) missing a ] so I had to make some guesses. In your question you explicitly state you want short entries on the same line, so that's what this does. If that isn't what you want, then you should clarify your question. – David Carlisle Jul 22 '17 at 7:57
  • @AnmolYadav see update – David Carlisle Jul 22 '17 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.