Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Literate.markdown with execute=true does not truncate array output #234

Closed
goerz opened this issue Jan 12, 2024 · 2 comments
Closed

Literate.markdown with execute=true does not truncate array output #234

goerz opened this issue Jan 12, 2024 · 2 comments

Comments

@goerz
Copy link

goerz commented Jan 12, 2024

Consider the following mwe_document.jl:

# # Minimum Working Example
#
# Print a long array:

rand(1000)

# Print a long matrix:

rand(2, 1000)

Executing this with

using Literate
Literate.markdown("mwe_document.jl", "."; execute=true)

produces a .md file that shows all values of the array and matrix. This is both non-ideal to look at and produces a large file.

In contrast, running the code in a terminal will show the array/matrix truncated, e.g.,

2×1000 Matrix{Float64}:
 0.336248  0.399099  0.91087   0.988818  …  0.679812  0.481316  0.0602483
 0.358077  0.333078  0.928913  0.810229     0.810204  0.830849  0.985508

The number of printed elements depends on the size of the terminal (see displaysize in IOContext).

A Jupyter notebook also truncates the output, apparently using the standard 80x24 terminal size.

Literate should set the IOContext during execution to mimic a standard terminal. The 80x24 size is probably a good default.

I'll have a look to see if I can fix this.

@fredrikekre
Copy link
Owner

Duplicate of #181

@fredrikekre fredrikekre marked this as a duplicate of #181 Jan 12, 2024
@goerz
Copy link
Author

goerz commented Jan 12, 2024

Agreed, it's a duplicate, and I figured out how to use DisplayAs as a workaround:

# # Minimum Working Example
#
# Print a long array:

import DisplayAs  # md

a = rand(1000)
#md a |> DisplayAs.withcontext(:limit => true) #hide

# Print a long matrix:

A = rand(2, 1000)
#md A |> DisplayAs.withcontext(:limit => true) #hide

I might still look into whether this has a better solution, since I agree with #181 (comment) that the default output should emulate the REPL.

But the need is less pressing than I thought initially.

Closing in favor of #181

@goerz goerz closed this as completed Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants