Format Code/PseudocodePut a grey background behind code extracts in a Latex document (like this site does)Pseudocode, special formattingAddition and subtraction of chemical equationsReplicate pseudocode formatPseudocode in LaTeXHow to format a pseudocode algorithmFormatting in Latex - PseudocodeHow to write pseudocode similar to code presented in “Beautiful Code” by J. R. HeardPseudocode vertical linesChange name in pseudocodeLatex formatting a pseudocode

What will the Frenchman say?

"Marked down as someone wanting to sell shares." What does that mean?

Would mining huge amounts of resources on the Moon change its orbit?

Homology of the fiber

What is the tangent at a sharp point on a curve?

Can other pieces capture a threatening piece and prevent a checkmate?

Why is this tree refusing to shed its dead leaves?

Air travel with refrigerated insulin

Hackerrank All Women's Codesprint 2019: Name the Product

Pre-Employment Background Check With Consent For Future Checks

Can "few" be used as a subject? If so, what is the rule?

label a part of commutative diagram

Justification failure in beamer enumerate list

Output visual diagram of picture

When did hardware antialiasing start being available?

Fair way to split coins

is this saw blade faulty?

Single word to change groups

PTIJ: Which Dr. Seuss books should one obtain?

UK Tourist Visa- Enquiry

Why is indicated airspeed rather than ground speed used during the takeoff roll?

Hot air balloons as primitive bombers

How can a new country break out from a developed country without war?

Print a physical multiplication table



Format Code/Pseudocode


Put a grey background behind code extracts in a Latex document (like this site does)Pseudocode, special formattingAddition and subtraction of chemical equationsReplicate pseudocode formatPseudocode in LaTeXHow to format a pseudocode algorithmFormatting in Latex - PseudocodeHow to write pseudocode similar to code presented in “Beautiful Code” by J. R. HeardPseudocode vertical linesChange name in pseudocodeLatex formatting a pseudocode













0















In a document containing a lot of other stuff, I have the following code which I have kept in verbatim(for lack of other ideas). As you can see, the alignment doesn't look so good.Image

How do I make it more presentable, so that it becomes more readable, with indentation perhaps(verbatim doesnt seem to handle spaces and tabs)?



documentclass[]article 
begindocument
beginverbatim

if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];


endverbatim
enddocument









share|improve this question
























  • A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "" on it).

    – DG'
    Feb 26 at 12:01











  • @DG' Is it more readable now? I wanna know how I could present it in a Latex Document, not on tex.stackexchange.

    – GermanShepherd
    Feb 26 at 12:13












  • Do you want LaTeX to indent it for you? It isn't the right tool for the job. There are editors out there that will support the programming language and will have auto-indentation for it, so why not using one of those?

    – TeXnician
    Feb 26 at 12:13






  • 1





    Well what I see in your screenshot is some verbatim code which you claim that one would see to be badly aligned. I do not get which kind of more readability you want. Making it stand out from ordinary text (maybe listings would help here) or making it nice in itself (external code formatting might be the way to go). Also your claim that verbatim can't handle spaces or tabs is wrong.

    – TeXnician
    Feb 26 at 12:23






  • 2





    For the automatic indenting you need to call an external tool, as neither listings or minted provides such functionality as far as I know. This can be done from within LaTeX with a (medium) bit of trouble. Which operating system do you use?

    – Marijn
    Feb 26 at 12:51















0















In a document containing a lot of other stuff, I have the following code which I have kept in verbatim(for lack of other ideas). As you can see, the alignment doesn't look so good.Image

How do I make it more presentable, so that it becomes more readable, with indentation perhaps(verbatim doesnt seem to handle spaces and tabs)?



documentclass[]article 
begindocument
beginverbatim

if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];


endverbatim
enddocument









share|improve this question
























  • A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "" on it).

    – DG'
    Feb 26 at 12:01











  • @DG' Is it more readable now? I wanna know how I could present it in a Latex Document, not on tex.stackexchange.

    – GermanShepherd
    Feb 26 at 12:13












  • Do you want LaTeX to indent it for you? It isn't the right tool for the job. There are editors out there that will support the programming language and will have auto-indentation for it, so why not using one of those?

    – TeXnician
    Feb 26 at 12:13






  • 1





    Well what I see in your screenshot is some verbatim code which you claim that one would see to be badly aligned. I do not get which kind of more readability you want. Making it stand out from ordinary text (maybe listings would help here) or making it nice in itself (external code formatting might be the way to go). Also your claim that verbatim can't handle spaces or tabs is wrong.

    – TeXnician
    Feb 26 at 12:23






  • 2





    For the automatic indenting you need to call an external tool, as neither listings or minted provides such functionality as far as I know. This can be done from within LaTeX with a (medium) bit of trouble. Which operating system do you use?

    – Marijn
    Feb 26 at 12:51













0












0








0


2






In a document containing a lot of other stuff, I have the following code which I have kept in verbatim(for lack of other ideas). As you can see, the alignment doesn't look so good.Image

How do I make it more presentable, so that it becomes more readable, with indentation perhaps(verbatim doesnt seem to handle spaces and tabs)?



documentclass[]article 
begindocument
beginverbatim

if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];


endverbatim
enddocument









share|improve this question
















In a document containing a lot of other stuff, I have the following code which I have kept in verbatim(for lack of other ideas). As you can see, the alignment doesn't look so good.Image

How do I make it more presentable, so that it becomes more readable, with indentation perhaps(verbatim doesnt seem to handle spaces and tabs)?



documentclass[]article 
begindocument
beginverbatim

if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];


endverbatim
enddocument






formatting pseudocode






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 7 mins ago







GermanShepherd

















asked Feb 26 at 11:58









GermanShepherdGermanShepherd

545220




545220












  • A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "" on it).

    – DG'
    Feb 26 at 12:01











  • @DG' Is it more readable now? I wanna know how I could present it in a Latex Document, not on tex.stackexchange.

    – GermanShepherd
    Feb 26 at 12:13












  • Do you want LaTeX to indent it for you? It isn't the right tool for the job. There are editors out there that will support the programming language and will have auto-indentation for it, so why not using one of those?

    – TeXnician
    Feb 26 at 12:13






  • 1





    Well what I see in your screenshot is some verbatim code which you claim that one would see to be badly aligned. I do not get which kind of more readability you want. Making it stand out from ordinary text (maybe listings would help here) or making it nice in itself (external code formatting might be the way to go). Also your claim that verbatim can't handle spaces or tabs is wrong.

    – TeXnician
    Feb 26 at 12:23






  • 2





    For the automatic indenting you need to call an external tool, as neither listings or minted provides such functionality as far as I know. This can be done from within LaTeX with a (medium) bit of trouble. Which operating system do you use?

    – Marijn
    Feb 26 at 12:51

















  • A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "" on it).

    – DG'
    Feb 26 at 12:01











  • @DG' Is it more readable now? I wanna know how I could present it in a Latex Document, not on tex.stackexchange.

    – GermanShepherd
    Feb 26 at 12:13












  • Do you want LaTeX to indent it for you? It isn't the right tool for the job. There are editors out there that will support the programming language and will have auto-indentation for it, so why not using one of those?

    – TeXnician
    Feb 26 at 12:13






  • 1





    Well what I see in your screenshot is some verbatim code which you claim that one would see to be badly aligned. I do not get which kind of more readability you want. Making it stand out from ordinary text (maybe listings would help here) or making it nice in itself (external code formatting might be the way to go). Also your claim that verbatim can't handle spaces or tabs is wrong.

    – TeXnician
    Feb 26 at 12:23






  • 2





    For the automatic indenting you need to call an external tool, as neither listings or minted provides such functionality as far as I know. This can be done from within LaTeX with a (medium) bit of trouble. Which operating system do you use?

    – Marijn
    Feb 26 at 12:51
















A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "" on it).

– DG'
Feb 26 at 12:01





A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "" on it).

– DG'
Feb 26 at 12:01













@DG' Is it more readable now? I wanna know how I could present it in a Latex Document, not on tex.stackexchange.

– GermanShepherd
Feb 26 at 12:13






@DG' Is it more readable now? I wanna know how I could present it in a Latex Document, not on tex.stackexchange.

– GermanShepherd
Feb 26 at 12:13














Do you want LaTeX to indent it for you? It isn't the right tool for the job. There are editors out there that will support the programming language and will have auto-indentation for it, so why not using one of those?

– TeXnician
Feb 26 at 12:13





Do you want LaTeX to indent it for you? It isn't the right tool for the job. There are editors out there that will support the programming language and will have auto-indentation for it, so why not using one of those?

– TeXnician
Feb 26 at 12:13




1




1





Well what I see in your screenshot is some verbatim code which you claim that one would see to be badly aligned. I do not get which kind of more readability you want. Making it stand out from ordinary text (maybe listings would help here) or making it nice in itself (external code formatting might be the way to go). Also your claim that verbatim can't handle spaces or tabs is wrong.

– TeXnician
Feb 26 at 12:23





Well what I see in your screenshot is some verbatim code which you claim that one would see to be badly aligned. I do not get which kind of more readability you want. Making it stand out from ordinary text (maybe listings would help here) or making it nice in itself (external code formatting might be the way to go). Also your claim that verbatim can't handle spaces or tabs is wrong.

– TeXnician
Feb 26 at 12:23




2




2





For the automatic indenting you need to call an external tool, as neither listings or minted provides such functionality as far as I know. This can be done from within LaTeX with a (medium) bit of trouble. Which operating system do you use?

– Marijn
Feb 26 at 12:51





For the automatic indenting you need to call an external tool, as neither listings or minted provides such functionality as far as I know. This can be done from within LaTeX with a (medium) bit of trouble. Which operating system do you use?

– Marijn
Feb 26 at 12:51










3 Answers
3






active

oldest

votes


















5














Something like this?



documentclassbook
usepackagelistings

lstdefinestylemyListingStyle

basicstyle = smallttfamily,
breaklines = true,


begindocument

beginlstlisting[
style = myListingStyle,
caption = Nice listing.
]
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting

enddocument


enter image description here



See Put a grey background behind code extracts in a Latex document (like this site does) for example for adding a background color. It's also possible to load the code from an external file -- just have a look at related questions.






share|improve this answer

























  • Is it possible to remove the caption for listings?

    – GermanShepherd
    Feb 26 at 12:35











  • @GermanShepherd Yes, just have a look at the code and remove caption = Nice listing..

    – Dr. Manuel Kuehner
    Feb 26 at 12:36


















9














Verbatim



Contrary to what you claim in your question, verbatim supports spaces and indentation, so why not use it?



verbatim



documentclass[]article 
begindocument
beginverbatim
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endverbatim
enddocument


Listings



The listings package can add colors.



listings



documentclass[]article
usepackagelistings
usepackagexcolor
lstsetbasicstyle=ttfamily,language=c,keywordstyle=colorblue
begindocument
beginlstlisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting
enddocument


Minted



The minted package is even more powerful…



minted



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
begindocument
beginmintedc
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endminted
enddocument


Tcblisting



You can of course combine it with tcolorbox or something else…



tcblisting



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
usepackage[minted]tcolorbox
newtcblistingmylistinglisting only,listing engine=minted, minted language=c,colback=gray!20
begindocument
beginmylisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endmylisting
enddocument





share|improve this answer




















  • 1





    +1: Very complete answer :)

    – Dr. Manuel Kuehner
    Feb 26 at 12:36






  • 2





    @Dr.ManuelKuehner By far not, but listing some common options :)

    – TeXnician
    Feb 26 at 12:37


















1














As already stated by others, verbatim does work for code (I use it for that purpose). The issue you see is that you usually format your code with tabs which verbatim is ignoring for some reason. So what I do is I put my code into verbatim select it and replace tabs with say 4 (or any number for that matter) of spaces (but just inside the selection).






share|improve this answer

























  • Are you sure that verbatim does not support tabs? In my case, it does.

    – JouleV
    Feb 26 at 16:16











  • i wrote a 80page script About the use of a finite element Analysis program that included a LOT of example Code with tabs. and i had to replace them all because else my Output would look like the one that the OP shared. this may depend on the tex Distribution however.

    – der bender
    Feb 26 at 16:18










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f476745%2fformat-code-pseudocode%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









5














Something like this?



documentclassbook
usepackagelistings

lstdefinestylemyListingStyle

basicstyle = smallttfamily,
breaklines = true,


begindocument

beginlstlisting[
style = myListingStyle,
caption = Nice listing.
]
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting

enddocument


enter image description here



See Put a grey background behind code extracts in a Latex document (like this site does) for example for adding a background color. It's also possible to load the code from an external file -- just have a look at related questions.






share|improve this answer

























  • Is it possible to remove the caption for listings?

    – GermanShepherd
    Feb 26 at 12:35











  • @GermanShepherd Yes, just have a look at the code and remove caption = Nice listing..

    – Dr. Manuel Kuehner
    Feb 26 at 12:36















5














Something like this?



documentclassbook
usepackagelistings

lstdefinestylemyListingStyle

basicstyle = smallttfamily,
breaklines = true,


begindocument

beginlstlisting[
style = myListingStyle,
caption = Nice listing.
]
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting

enddocument


enter image description here



See Put a grey background behind code extracts in a Latex document (like this site does) for example for adding a background color. It's also possible to load the code from an external file -- just have a look at related questions.






share|improve this answer

























  • Is it possible to remove the caption for listings?

    – GermanShepherd
    Feb 26 at 12:35











  • @GermanShepherd Yes, just have a look at the code and remove caption = Nice listing..

    – Dr. Manuel Kuehner
    Feb 26 at 12:36













5












5








5







Something like this?



documentclassbook
usepackagelistings

lstdefinestylemyListingStyle

basicstyle = smallttfamily,
breaklines = true,


begindocument

beginlstlisting[
style = myListingStyle,
caption = Nice listing.
]
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting

enddocument


enter image description here



See Put a grey background behind code extracts in a Latex document (like this site does) for example for adding a background color. It's also possible to load the code from an external file -- just have a look at related questions.






share|improve this answer















Something like this?



documentclassbook
usepackagelistings

lstdefinestylemyListingStyle

basicstyle = smallttfamily,
breaklines = true,


begindocument

beginlstlisting[
style = myListingStyle,
caption = Nice listing.
]
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting

enddocument


enter image description here



See Put a grey background behind code extracts in a Latex document (like this site does) for example for adding a background color. It's also possible to load the code from an external file -- just have a look at related questions.







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 26 at 12:46

























answered Feb 26 at 12:28









Dr. Manuel KuehnerDr. Manuel Kuehner

9,25932769




9,25932769












  • Is it possible to remove the caption for listings?

    – GermanShepherd
    Feb 26 at 12:35











  • @GermanShepherd Yes, just have a look at the code and remove caption = Nice listing..

    – Dr. Manuel Kuehner
    Feb 26 at 12:36

















  • Is it possible to remove the caption for listings?

    – GermanShepherd
    Feb 26 at 12:35











  • @GermanShepherd Yes, just have a look at the code and remove caption = Nice listing..

    – Dr. Manuel Kuehner
    Feb 26 at 12:36
















Is it possible to remove the caption for listings?

– GermanShepherd
Feb 26 at 12:35





Is it possible to remove the caption for listings?

– GermanShepherd
Feb 26 at 12:35













@GermanShepherd Yes, just have a look at the code and remove caption = Nice listing..

– Dr. Manuel Kuehner
Feb 26 at 12:36





@GermanShepherd Yes, just have a look at the code and remove caption = Nice listing..

– Dr. Manuel Kuehner
Feb 26 at 12:36











9














Verbatim



Contrary to what you claim in your question, verbatim supports spaces and indentation, so why not use it?



verbatim



documentclass[]article 
begindocument
beginverbatim
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endverbatim
enddocument


Listings



The listings package can add colors.



listings



documentclass[]article
usepackagelistings
usepackagexcolor
lstsetbasicstyle=ttfamily,language=c,keywordstyle=colorblue
begindocument
beginlstlisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting
enddocument


Minted



The minted package is even more powerful…



minted



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
begindocument
beginmintedc
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endminted
enddocument


Tcblisting



You can of course combine it with tcolorbox or something else…



tcblisting



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
usepackage[minted]tcolorbox
newtcblistingmylistinglisting only,listing engine=minted, minted language=c,colback=gray!20
begindocument
beginmylisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endmylisting
enddocument





share|improve this answer




















  • 1





    +1: Very complete answer :)

    – Dr. Manuel Kuehner
    Feb 26 at 12:36






  • 2





    @Dr.ManuelKuehner By far not, but listing some common options :)

    – TeXnician
    Feb 26 at 12:37















9














Verbatim



Contrary to what you claim in your question, verbatim supports spaces and indentation, so why not use it?



verbatim



documentclass[]article 
begindocument
beginverbatim
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endverbatim
enddocument


Listings



The listings package can add colors.



listings



documentclass[]article
usepackagelistings
usepackagexcolor
lstsetbasicstyle=ttfamily,language=c,keywordstyle=colorblue
begindocument
beginlstlisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting
enddocument


Minted



The minted package is even more powerful…



minted



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
begindocument
beginmintedc
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endminted
enddocument


Tcblisting



You can of course combine it with tcolorbox or something else…



tcblisting



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
usepackage[minted]tcolorbox
newtcblistingmylistinglisting only,listing engine=minted, minted language=c,colback=gray!20
begindocument
beginmylisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endmylisting
enddocument





share|improve this answer




















  • 1





    +1: Very complete answer :)

    – Dr. Manuel Kuehner
    Feb 26 at 12:36






  • 2





    @Dr.ManuelKuehner By far not, but listing some common options :)

    – TeXnician
    Feb 26 at 12:37













9












9








9







Verbatim



Contrary to what you claim in your question, verbatim supports spaces and indentation, so why not use it?



verbatim



documentclass[]article 
begindocument
beginverbatim
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endverbatim
enddocument


Listings



The listings package can add colors.



listings



documentclass[]article
usepackagelistings
usepackagexcolor
lstsetbasicstyle=ttfamily,language=c,keywordstyle=colorblue
begindocument
beginlstlisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting
enddocument


Minted



The minted package is even more powerful…



minted



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
begindocument
beginmintedc
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endminted
enddocument


Tcblisting



You can of course combine it with tcolorbox or something else…



tcblisting



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
usepackage[minted]tcolorbox
newtcblistingmylistinglisting only,listing engine=minted, minted language=c,colback=gray!20
begindocument
beginmylisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endmylisting
enddocument





share|improve this answer















Verbatim



Contrary to what you claim in your question, verbatim supports spaces and indentation, so why not use it?



verbatim



documentclass[]article 
begindocument
beginverbatim
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endverbatim
enddocument


Listings



The listings package can add colors.



listings



documentclass[]article
usepackagelistings
usepackagexcolor
lstsetbasicstyle=ttfamily,language=c,keywordstyle=colorblue
begindocument
beginlstlisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting
enddocument


Minted



The minted package is even more powerful…



minted



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
begindocument
beginmintedc
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endminted
enddocument


Tcblisting



You can of course combine it with tcolorbox or something else…



tcblisting



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
usepackage[minted]tcolorbox
newtcblistingmylistinglisting only,listing engine=minted, minted language=c,colback=gray!20
begindocument
beginmylisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endmylisting
enddocument






share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 26 at 12:36

























answered Feb 26 at 12:29









TeXnicianTeXnician

25.7k63390




25.7k63390







  • 1





    +1: Very complete answer :)

    – Dr. Manuel Kuehner
    Feb 26 at 12:36






  • 2





    @Dr.ManuelKuehner By far not, but listing some common options :)

    – TeXnician
    Feb 26 at 12:37












  • 1





    +1: Very complete answer :)

    – Dr. Manuel Kuehner
    Feb 26 at 12:36






  • 2





    @Dr.ManuelKuehner By far not, but listing some common options :)

    – TeXnician
    Feb 26 at 12:37







1




1





+1: Very complete answer :)

– Dr. Manuel Kuehner
Feb 26 at 12:36





+1: Very complete answer :)

– Dr. Manuel Kuehner
Feb 26 at 12:36




2




2





@Dr.ManuelKuehner By far not, but listing some common options :)

– TeXnician
Feb 26 at 12:37





@Dr.ManuelKuehner By far not, but listing some common options :)

– TeXnician
Feb 26 at 12:37











1














As already stated by others, verbatim does work for code (I use it for that purpose). The issue you see is that you usually format your code with tabs which verbatim is ignoring for some reason. So what I do is I put my code into verbatim select it and replace tabs with say 4 (or any number for that matter) of spaces (but just inside the selection).






share|improve this answer

























  • Are you sure that verbatim does not support tabs? In my case, it does.

    – JouleV
    Feb 26 at 16:16











  • i wrote a 80page script About the use of a finite element Analysis program that included a LOT of example Code with tabs. and i had to replace them all because else my Output would look like the one that the OP shared. this may depend on the tex Distribution however.

    – der bender
    Feb 26 at 16:18















1














As already stated by others, verbatim does work for code (I use it for that purpose). The issue you see is that you usually format your code with tabs which verbatim is ignoring for some reason. So what I do is I put my code into verbatim select it and replace tabs with say 4 (or any number for that matter) of spaces (but just inside the selection).






share|improve this answer

























  • Are you sure that verbatim does not support tabs? In my case, it does.

    – JouleV
    Feb 26 at 16:16











  • i wrote a 80page script About the use of a finite element Analysis program that included a LOT of example Code with tabs. and i had to replace them all because else my Output would look like the one that the OP shared. this may depend on the tex Distribution however.

    – der bender
    Feb 26 at 16:18













1












1








1







As already stated by others, verbatim does work for code (I use it for that purpose). The issue you see is that you usually format your code with tabs which verbatim is ignoring for some reason. So what I do is I put my code into verbatim select it and replace tabs with say 4 (or any number for that matter) of spaces (but just inside the selection).






share|improve this answer















As already stated by others, verbatim does work for code (I use it for that purpose). The issue you see is that you usually format your code with tabs which verbatim is ignoring for some reason. So what I do is I put my code into verbatim select it and replace tabs with say 4 (or any number for that matter) of spaces (but just inside the selection).







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 26 at 16:13









JouleV

6,46121750




6,46121750










answered Feb 26 at 16:09









der benderder bender

679




679












  • Are you sure that verbatim does not support tabs? In my case, it does.

    – JouleV
    Feb 26 at 16:16











  • i wrote a 80page script About the use of a finite element Analysis program that included a LOT of example Code with tabs. and i had to replace them all because else my Output would look like the one that the OP shared. this may depend on the tex Distribution however.

    – der bender
    Feb 26 at 16:18

















  • Are you sure that verbatim does not support tabs? In my case, it does.

    – JouleV
    Feb 26 at 16:16











  • i wrote a 80page script About the use of a finite element Analysis program that included a LOT of example Code with tabs. and i had to replace them all because else my Output would look like the one that the OP shared. this may depend on the tex Distribution however.

    – der bender
    Feb 26 at 16:18
















Are you sure that verbatim does not support tabs? In my case, it does.

– JouleV
Feb 26 at 16:16





Are you sure that verbatim does not support tabs? In my case, it does.

– JouleV
Feb 26 at 16:16













i wrote a 80page script About the use of a finite element Analysis program that included a LOT of example Code with tabs. and i had to replace them all because else my Output would look like the one that the OP shared. this may depend on the tex Distribution however.

– der bender
Feb 26 at 16:18





i wrote a 80page script About the use of a finite element Analysis program that included a LOT of example Code with tabs. and i had to replace them all because else my Output would look like the one that the OP shared. this may depend on the tex Distribution however.

– der bender
Feb 26 at 16:18

















draft saved

draft discarded
















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f476745%2fformat-code-pseudocode%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How should I use the fbox command correctly to avoid producing a Bad Box message?How to put a long piece of text in a box?How to specify height and width of fboxIs there an arrayrulecolor-like command to change the rule color of fbox?What is the command to highlight bad boxes in pdf?Why does fbox sometimes place the box *over* the graphic image?how to put the text in the boxHow to create command for a box where text inside the box can automatically adjust?how can I make an fbox like command with certain color, shape and width of border?how to use fbox in align modeFbox increase the spacing between the box and it content (inner margin)how to change the box height of an equationWhat is the use of the hbox in a newcommand command?

152 Atala Notae | Nexus externi | Tabula navigationis"Discovery Circumstances: Numbered Minor Planets"2000152Small-Body Database

Doxepinum Nexus interni Notae | Tabula navigationis3158DB01142WHOa682390"Structural Analysis of the Histamine H1 Receptor""Transdermal and Topical Drug Administration in the Treatment of Pain""Antidepressants as antipruritic agents: A review"