0

I'm using the mcode package for including my codes into my documents, but the problem is that when my codes are too long, and they need more than one page the program tries to keep them in one page, ergo the last lines of the codes are missing and it does not break into 2 pages.

I read the documentation but I couldn't find the answer and I have the same problem with listings package too.

I reviewed some question about minted but they weren't helpful in this case for me.

  ‎\documentclass{book}‎

‎\usepackage{graphicx}‎ 
‎\usepackage{amsmath,amssymb}‎ 
‎\usepackage{caption}‎
‎\usepackage{color,xecolor}‎
‎\usepackage[numbered,autolinebreaks,useliterate]{mcode}‎

‎\begin{document}‎

‎\begin{figure}‎
‎\caption{A very very long code is here}‎
‎\lstinputlisting{longcode.m}‎
‎\end{figure}‎

‎\end{document}

and here is the code which can be saved in a longcode.m file since I cannot attach anything here :(

    %% LTE_sim _main _launcher
    % eNodeB Power transmission uniformly distributed
LTE_config.switch_off_eNodeBs = 5;
LTE_config.eNodeB_arrangment = 0;   % Hexagonal Ring
LTE_config.UE_walkingModel = 0;     % Mobility model        

%% LTE_load _params
LTE_config.TTI_length = 1e-3;       % SubFrame length
    % Simulation duration
LTE_config.simulation_time_tti = 100000;   
LTE_config.frequency = 2e9;         % Carrier Frequency
LTE_config.bandwidth = 10e6;        % Bandwidth
LTE_config.UE_speed = 30/3.6;       % UE speed (Km/H => m/s)  
LTE_config.nr_UEs = 100;            % Number of UEs   
    % inter eNodeB distance (Cell radius=.5)
LTE_config.inter_eNodeB_distance = 2*sqrt (500^2+(500/4)^2);  
    % eNodeB Power transmission (43dbm)
LTE_config.eNodeB_tx_power = 19.9526;        
    % Propagation Model
LTE_config.macroscopic_pathloss_model = 'cost231';                         
LTE_config.macroscopic_pathloss_model _settings.environment = ...
   'urban_macro';

%% LTE_init _load _BLER _curves
BLER_threshold = 0.1;              % Target BLER                                                  
target_BLER = 0.1;                 % Target BLER                                               

%% Parameters that are ok
% simulator assume subcarrier spacing of 15 kHz
% Modulation Schemes is QPSK, 16QAM, and 64QAM

%% I am not sure :-s

% Symbols for TTI
LTE_config.cyclic_prefix   = 'normal';
switch LTE_config.cyclic_prefix
    case 'normal'
        LTE_config.N_sym = 14;
    case 'extended'
        LTE_config.N_sym = 6;
    otherwise
        error ('CP can only be "normal" or "extended"');
end
% CQI Measurement period
LTE_config.unquantized_CQI_feedback = fulse;
    % UE class
    unquantized_CQI _feedback = fulse;

%% I don't khnow

% Control Overhead
% Traffic Models
% CQI Method
% Frequency Reuse Scheme
% LTE_config.switch_off_eNodeBs = 5;
LTE_config.eNodeB_arrangment = 0;   % Hexagonal Ring
LTE_config.UE_walkingModel = 0;     % Mobility model        

%% LTE_load _params
LTE_config.TTI_length = 1e-3;       % SubFrame length
    % Simulation duration
LTE_config.simulation_time_tti = 100000;   
LTE_config.frequency = 2e9;         % Carrier Frequency
LTE_config.bandwidth = 10e6;        % Bandwidth
LTE_config.UE_speed = 30/3.6;       % UE speed (Km/H => m/s)  
LTE_config.nr_UEs = 100;            % Number of UEs   
    % inter eNodeB distance (Cell radius=.5)
LTE_config.inter_eNodeB_distance = 2*sqrt (500^2+(500/4)^2);  
    % eNodeB Power transmission (43dbm)
LTE_config.eNodeB_tx_power = 19.9526;        
    % Propagation Model
LTE_config.macroscopic_pathloss_model = 'cost231';                         
LTE_config.macroscopic_pathloss_model _settings.environment = ...
   'urban_macro';

%% LTE_init _load _BLER _curves
BLER_threshold = 0.1;              % Target BLER                                                  
target_BLER = 0.1;                 % Target BLER                                               

%% Parameters that are ok
% simulator assume subcarrier spacing of 15 kHz
% Modulation Schemes is QPSK, 16QAM, and 64QAM

%% I am not sure :-s

% Symbols for TTI
LTE_config.cyclic_prefix   = 'normal';
switch LTE_config.cyclic_prefix
    case 'normal'
        LTE_config.N_sym = 14;
    case 'extended'
        LTE_config.N_sym = 6;
    otherwise
        error ('CP can only be "normal" or "extended"');
end
% CQI Measurement period
LTE_config.unquantized_CQI_feedback = fulse;
    % UE class
    unquantized_CQI _feedback = fulse;

%% I don't khnow

% Control Overhead
% Traffic Models
% CQI Method
% Frequency Reuse Scheme
% 

And this is what happens to the page : enter image description here

So how can I break these codes into 2 pages?

  • 3
    listings has options to break over a page but latex floats such as figure are boxes so never break. You need to take it out of the figure. – David Carlisle Jun 21 '13 at 19:11
  • You might be interested in the matlab-prettifier package; see this answer. – jubobs Apr 28 '14 at 17:13
2

figure, as commented by David Carlisle, is a float and will be put in a box making it unable to be broken across the pages. Removing figure and using the caption from listings package as:

\lstinputlisting[caption=A very very long code is here]{longcode.m}

will do the job.

Full code:

\documentclass{book}
%\usepackage{graphicx}‎
%\usepackage{amsmath,amssymb}‎
%\usepackage{caption}‎
%\usepackage{color,xcolor}
\usepackage[numbered,autolinebreaks,useliterate]{mcode}
\usepackage{filecontents}
\begin{filecontents*}{longcode.m}
    %% LTE_sim _main _launcher
    % eNodeB Power transmission uniformly distributed
LTE_config.switch_off_eNodeBs = 5;
LTE_config.eNodeB_arrangment = 0;   % Hexagonal Ring
LTE_config.UE_walkingModel = 0;     % Mobility model

%% LTE_load _params
LTE_config.TTI_length = 1e-3;       % SubFrame length
    % Simulation duration
LTE_config.simulation_time_tti = 100000;
LTE_config.frequency = 2e9;         % Carrier Frequency
LTE_config.bandwidth = 10e6;        % Bandwidth
LTE_config.UE_speed = 30/3.6;       % UE speed (Km/H => m/s)
LTE_config.nr_UEs = 100;            % Number of UEs
    % inter eNodeB distance (Cell radius=.5)
LTE_config.inter_eNodeB_distance = 2*sqrt (500^2+(500/4)^2);
    % eNodeB Power transmission (43dbm)
LTE_config.eNodeB_tx_power = 19.9526;
    % Propagation Model
LTE_config.macroscopic_pathloss_model = 'cost231';
LTE_config.macroscopic_pathloss_model _settings.environment = ...
   'urban_macro';

%% LTE_init _load _BLER _curves
BLER_threshold = 0.1;              % Target BLER
target_BLER = 0.1;                 % Target BLER

%% Parameters that are ok
% simulator assume subcarrier spacing of 15 kHz
% Modulation Schemes is QPSK, 16QAM, and 64QAM

%% I am not sure :-s

% Symbols for TTI
LTE_config.cyclic_prefix   = 'normal';
switch LTE_config.cyclic_prefix
    case 'normal'
        LTE_config.N_sym = 14;
    case 'extended'
        LTE_config.N_sym = 6;
    otherwise
        error ('CP can only be "normal" or "extended"');
end
% CQI Measurement period
LTE_config.unquantized_CQI_feedback = fulse;
    % UE class
    unquantized_CQI _feedback = fulse;

%% I don't khnow

% Control Overhead
% Traffic Models
% CQI Method
% Frequency Reuse Scheme
% LTE_config.switch_off_eNodeBs = 5;
LTE_config.eNodeB_arrangment = 0;   % Hexagonal Ring
LTE_config.UE_walkingModel = 0;     % Mobility model

%% LTE_load _params
LTE_config.TTI_length = 1e-3;       % SubFrame length
    % Simulation duration
LTE_config.simulation_time_tti = 100000;
LTE_config.frequency = 2e9;         % Carrier Frequency
LTE_config.bandwidth = 10e6;        % Bandwidth
LTE_config.UE_speed = 30/3.6;       % UE speed (Km/H => m/s)
LTE_config.nr_UEs = 100;            % Number of UEs
    % inter eNodeB distance (Cell radius=.5)
LTE_config.inter_eNodeB_distance = 2*sqrt (500^2+(500/4)^2);
    % eNodeB Power transmission (43dbm)
LTE_config.eNodeB_tx_power = 19.9526;
    % Propagation Model
LTE_config.macroscopic_pathloss_model = 'cost231';
LTE_config.macroscopic_pathloss_model _settings.environment = ...
   'urban_macro';

%% LTE_init _load _BLER _curves
BLER_threshold = 0.1;              % Target BLER
target_BLER = 0.1;                 % Target BLER

%% Parameters that are ok
% simulator assume subcarrier spacing of 15 kHz
% Modulation Schemes is QPSK, 16QAM, and 64QAM

%% I am not sure :-s

% Symbols for TTI
LTE_config.cyclic_prefix   = 'normal';
switch LTE_config.cyclic_prefix
    case 'normal'
        LTE_config.N_sym = 14;
    case 'extended'
        LTE_config.N_sym = 6;
    otherwise
        error ('CP can only be "normal" or "extended"');
end
% CQI Measurement period
LTE_config.unquantized_CQI_feedback = fulse;
    % UE class
    unquantized_CQI _feedback = fulse;

%% I don't khnow

% Control Overhead
% Traffic Models
% CQI Method
% Frequency Reuse Scheme
% 
\end{filecontents*}
\begin{document}‎
‎\lstinputlisting[caption=A very very long code is here
]{longcode.m}
\end{document}

enter image description here

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.